Skip to content

domfarolino/angular2-login-seed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#angular2-login-seed

MIT license Dependency Status devDependency Status Angular2 Style Guide

A seed application for developers to get started building applications with Angular2. The application's backend is in Node.js featuring user login via PassportJS and OAuth.

angular2-login-seed

Table of Contents

  1. Demo
  2. Technologies
  3. Adding OAuth Providers
  4. TL;DR Get started now
  5. Angular Component Tree
  6. Directory Structure
  7. Contributing
  8. Todo

Demo

Check this site out live here

Technologies

Some of the open source technologies used in this application are listed below

  1. Angular 2
  2. Angular Material2
  3. Node.js
  4. Express
  5. Passport
  6. Sequelize

TL;DR Get started now

# Fork or clone this repo git clone git@github.com:domfarolino/angular2-login-seed.git npm install

Next, either input your Google and Twitter application's OAuth credentials in the config/default.json file, or follow this guide to set up an OAuth application with Google and Twitter.

You'll need either a local or production database which the application will use to store users. The structure of this database is defined in the angular2-login-seed.sql file found in the root folder. Execute its sql contents on a database to create a users table to house your users.

To learn about how the npm package config works click here

Next fill out either the config/default.json, config/production.json or both with database credentials so that Sequelize knows how to connect to your database when you're in development or production mode. You'll also want to fill out the oauthCallbacks object with callback URLs for your app. The finished product should look something like this:

{ "database-configuration": { "host": "localhost", "user": "user", "pass": "pass", "name": "dbName" }, "oauthCredentials": { "twitter": { "id": "<>", "secret": "<>" }, "google": { "id": "<>", "secret": "<>" } }, "oauthCallbacks": { "googleCallbackUrl" : "http://localhost:5000/callback/google", "twitterCallbackUrl" : "http://localhost:5000/callback/twitter", "facebookCallbackUrl": "http://localhost:5000/callback/facebook" } }

Your config/production.json should only contain data that will overwrite any of the default data when you're in production mode.

Then type one of the following commands into the terminal:

npm run # run in production mode, uses default.json values unless they're overridden in production.json

Or

npm run dev # run in development mode, uses default.json values only

That should be it! Just browse to http://localhost:5000 to see the app.

Further development

For further development, open a new terminal window and type npm run front. This will transpile and "watch" all of your typescript files for any changes.

Adding OAuth Providers

I've tried to make it as easy as possible to add more OAuth providers to this app to keep it flexible. If you think it can be done better please submit a PR to improve the maintainability of the app. To add support for another OAuth provider 4 things need to be done:

1. Add authorization and callback routes for the provider (edit /routes/index.js)
/** * Authorization route for <provider> provider */ router.get('/authorize/provider', passport.authenticate('provider')); /** * Define our provider callback endpoint and success/failure methods */ router.get('/callback/provider',	passport.authenticate('provider', {	successRedirect: '/',	failureRedirect: '/provider' })); 
2. Add your OAuth credentials to the /config/default.json file. You'll use these in /config/passport.js which you'll edit next
3. Setup/use PassportJS strategy in /config/passport.js
passport.use(new ProviderStrategy({.... 
4. Update the attribute utility functions at the end of /config/passport.js to support your provider

This entails basically examining the JSON payload you get back from your provider and seeing under what keys, the information you need to insert into the database exists under. If any database/model changes need made modify the database appropriately and update the User model /models.js

Angular Component Tree

app-component-tree

Directory Structure

The goal is to keep as flat of a directory structure as possible for all of the Angular components. Reasons for this, as well as grouping files by bounded context can be found here.

. ├─.gitignore ├─144.png ├─192.png ├─96.png ├─angular2-login-seed.sql ├─app-component-tree.png ├─app.js ├─bin │ ├─www ├─client │ ├─app │ │ ├─app.component.css │ │ ├─app.component.html │ │ ├─app.component.js │ │ ├─app.component.js.map │ │ ├─app.component.ts │ ├─assets │ │ ├─favicon.ico │ │ ├─img │ │ │ ├─background.jpg │ │ │ ├─bg.png │ │ │ ├─menu_bg.jpg │ │ │ ├─menu_bg_small.jpg │ │ │ ├─space_bg.jpg │ ├─dashboard │ │ ├─dashboard.component.html │ │ ├─dashboard.component.js │ │ ├─dashboard.component.js.map │ │ ├─dashboard.component.ts │ ├─hero-detail │ │ ├─hero-detail.component.css │ │ ├─hero-detail.component.html │ │ ├─hero-detail.component.js │ │ ├─hero-detail.component.js.map │ │ ├─hero-detail.component.ts │ ├─heroes │ │ ├─heroes.component.css │ │ ├─heroes.component.html │ │ ├─heroes.component.js │ │ ├─heroes.component.js.map │ │ ├─heroes.component.ts │ ├─home-root │ │ ├─home-root.component.css │ │ ├─home-root.component.html │ │ ├─home-root.component.js │ │ ├─home-root.component.js.map │ │ ├─home-root.component.ts │ ├─login │ │ ├─login.component.css │ │ ├─login.component.html │ │ ├─login.component.js │ │ ├─login.component.js.map │ │ ├─login.component.ts │ ├─main.js │ ├─main.js.map │ ├─main.ts │ ├─register │ │ ├─register.component.css │ │ ├─register.component.html │ │ ├─register.component.js │ │ ├─register.component.js.map │ │ ├─register.component.ts │ ├─shared │ │ ├─components │ │ │ ├─quick-card │ │ │ │ ├─quick-card.component.css │ │ │ │ ├─quick-card.component.html │ │ │ │ ├─quick-card.component.js │ │ │ │ ├─quick-card.component.js.map │ │ │ │ ├─quick-card.component.ts │ │ ├─services │ │ │ ├─hero │ │ │ │ ├─hero.js │ │ │ │ ├─hero.js.map │ │ │ │ ├─hero.service.js │ │ │ │ ├─hero.service.js.map │ │ │ │ ├─hero.service.ts │ │ │ │ ├─hero.ts │ │ │ ├─user │ │ │ │ ├─user-status-codes.js │ │ │ │ ├─user-status-codes.js.map │ │ │ │ ├─user-status-codes.ts │ │ │ │ ├─user.js │ │ │ │ ├─user.js.map │ │ │ │ ├─user.service.js │ │ │ │ ├─user.service.js.map │ │ │ │ ├─user.service.ts │ │ │ │ ├─user.ts │ │ │ │ ├─username-email-validator.js │ │ │ │ ├─username-email-validator.js.map │ │ │ │ ├─username-email-validator.ts │ ├─users │ │ ├─user-badge.component.css │ │ ├─user-badge.component.html │ │ ├─user-badge.component.js │ │ ├─user-badge.component.js.map │ │ ├─user-badge.component.ts │ │ ├─users.component.css │ │ ├─users.component.html │ │ ├─users.component.js │ │ ├─users.component.js.map │ │ ├─users.component.ts ├─config │ ├─default.json │ ├─passport.js │ ├─production.json ├─controllers │ ├─getAllUsersPublic.js │ ├─getUserPublic.js │ ├─index.js │ ├─registerUser.js │ ├─truncateUserObject.js │ ├─userExists.js ├─directoryStructure.txt ├─index.html ├─LICENSE ├─logo.png ├─logo_post_polymer.png ├─manifest.json ├─models │ ├─index.js │ ├─user.js ├─package.json ├─Procfile ├─README.md ├─routes │ ├─api │ │ ├─index.js │ │ ├─users.js │ ├─authenticationHelpers.js │ ├─authorize │ │ ├─index.js │ ├─index.js ├─sw.js ├─tsconfig.json ├─typings.json ├─views │ ├─error.ejs 

Contributing

Please feel free to contribute to this project to help build more defined practices we can use in larger Angular 2 web applications. PRs are welcome!

Todo

  1. User 'profile' page
  2. Angular 2 route security
  3. Progressive Web App - Service Worker Caching
  4. Progressive Web App - Push Notification support with encrypted payload
  5. Eventually implement angular/mobile-toolkit when more progress is made
  6. Update @angular/router-deprecated => @angular/router when rc router is near completion
  7. RxJS websocket integration for realtime user status
  8. Unit testing

About

(deprecated) Seed app w/ Angular2, Node, Express, and OAuth login

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •