MEAN stack message board (forum) application with Auth0 authentication and passwordless login.
Once you have created a free mLab account, create a new database with mLab.
- Log into mLab. In MongoDB Deployments, click the "Create new" button.
- Select your desired Cloud Provider and Region.
- Change the Plan to Single-node and select the free "Sandbox" option.
- Scroll down and give your database a name, like
mean
. - Click the "Create new MongoDB deployment" button.
The new database can now be selected from our deployments. It should look something like this:
We now need to add a user in order to connect to our database. Click on the database to edit it.
- Select the Users tab and click the "Add database user" button.
- Enter a database username and password in the modal. These credentials will be needed to read and write to the database with Node.
- Make a note of the database's MongoDB URI. This should be in the format:
mongodb:https://<dbuser>:<dbpassword>@<ds111111>.mlab.com:<port>/<dbname>
.
Now we're ready to use our MongoDB database.
Note: If you prefer, you can host MongoDB locally. Follow these instructions to install MongoDB on your operating system.
Once you've signed up for a free Auth0 account, you can implement Auth0 authentication with centralized login and passwordless.
- Go to your Auth0 Dashboard and click the "Create a New Client" button.
- Give your new app a name, select Single Page Web Applications, then click the "Create" button.
- In the Settings for your new Auth0 Client app, add
https://localhost:4200/callback, https://localhost:8085/callback
to the Allowed Callback URLs. - Add
https://localhost:4200, https://localhost:8085
to the Allowed Web Origins. - Add
https://localhost:4200, https://localhost:8085
to the Allowed Origins (CORS). - Make sure that Use Auth0 instead of the IdP to do Single Sign On is enabled.
- At the bottom of the Settings section, click the "Show Advanced Settings" link. Choose the OAuth tab and verify that the JsonWebToken Signature Algorithm is set to
RS256
. - Click the "Save Changes" button.
- Go to Connections -> Passwordless and toggle on Email.
- In the Email passwordless settings screen, add
{ "scope": "openid profile" }
to Authentication Parameters. - Click the "Save" button.
- Click the Apps tab at the top of the window and find your newly-created Client. Toggle the switch on.
- Click the "Save" button.
- Go to Hosted Pages. Toggle on the Customize Login Page option. This will enable you to modify the provided template.
- Using the Default Templates dropdown, switch to Lock (Passwordless).
- Click the "Save" button.
Go to APIs in your Auth0 Dashboard and click on the "Create API" button. Enter a name for the API. Set the Identifier to https://localhost:8085/api/
. The Signing Algorithm should be RS256
.
Clone this project and from the root, run the following command to install dependencies for the server and client-side:
$ npm install
- Open the
server/config.js.sample
file. Replace[AUTH0_DOMAIN]
with your Auth0 domain and replace[MONGODB_URI]
with your mLab MongoDB URI. Then remove.sample
from the file name. - Open the
src/app/auth/auth0-variables.ts.sample
file. Replace[AUTH0_CLIENT]
and[AUTH0_DOMAIN]
with your Auth0 Client ID and domain. Then remove.sample
from the file name.
- Start Node API server:
NODE_ENV=dev node server
from the root folder. - Start Angular server:
ng serve
from the root folder.
The API will run on localhost:8085
and the app will run on localhost:4200
.
- Run
ng build
to compile the Angular project from the root folder. - Start Node API and app server:
node server
from the root folder.
The app and API will both run on localhost:8085
.
This project is licensed under the MIT license. See the LICENSE file for more info.