Simple Auth Server

Built on

  • GraphQL
  • Typeorm
  • Typescript

Basic user authentication so it's one less thing to worry about

image

Getting Ahead

Test on your device via install or use the Expo go app

Register and authenticate users with the power of Graphql and Rest. With Redis and express-sessions keep users signed in. Connected to an emailing delivery system to send confirmation emails and reset password emails. Simple to add other email services to meet project needs such as email receipts or promotions.

Tech Stack

Tools used that helped make this server

Typescript

Typeorm

NodeJS

Express

Graphql

Postgres

SendGrid

REST

Heroku

Examples

Quick interactive way to test the server

To keep things simple suggest use this neat 10 min email generator .

10minemail does what the name implies and helps test receiving mail from an API without using your actual email address. The given email is open for 10 minutes, great for this use case.

Error Handling

For all abnormal requests, the API will return non-2xx status code, with a response body in JSON format to explain the error. The response will follow a format like:

{ "path": "error-path-here", "message": "error-msg-here" }

Using an invalid register request, all in all, a complete error response from the server would like:

{ "register": [ { "path": "error-path-here", "message": "error-msg-here" } ] }

Register

To try out the query, go ahead and enter an email. In this case, the email entered will be used as the password.

mutation RegisterUser($email: String!, $password: String!) { register(email: $email, password: $password) }

Response - 200

{ "data": { "register": null } }

Enter a email

Login

The login section requires you to use the email address which was registered. Enter both the email and password below to log in. For this purpose, the response will not be the expected 200 response from the mutation itself. But from a query that retrieves the email of the user logged in. Null as the response if the login was unsuccessful and user data otherwise.

mutation LoginUser($email: String!, $password: String!) { login(email: $email, password: $password) }

Response - 200

{ "data": { "login": null } }

Enter a email

Enter a password

Forgot Password

Creates an email containing a link to reset/change your password. For this particular case, there is no client-side. A way around this is to copy the link address in the email. Go ahead and add it to the field named "key" in the change password section below

mutation SendForgotPwdEmail($email: String!) { sendForgotPasswordEmail(email: $email) }

Response - 200

{ "data": { "sendForgotPasswordEmail": true } }

Enter a email

Change Password

Here you will need to use the key taken from the pathname. If you need the key follow the steps above to get it from the email. Once completed, enter both the key and new password to the fields below.

mutation ChangePassword($newPassword: String!, $key: String!) { changeForgottenPassword(newPassword: $newPassword, key: $key) }

Response - 200

{ "data": { "changeForgottenPassword": null } }

Enter a new password

Enter a key