Mongo Server
  • Introduction
  • Getting started
  • Basics
    • Routing and Queries
    • Restrict endpoints
    • Route logic
    • Default values
    • Input validation and Output Formatting
  • Auth and permissions
    • Login and authentication
    • Permission handling
    • Local authentication
    • Magic Links and codes
  • Automatic Documentation
    • Server description
    • Swagger Docs
  • Miscellaneous
    • Db Seeding
    • Mailing settings
    • Roadmap
    • Population Constrains
Powered by GitBook
On this page
  • Magic Code auth
  • Magic link auth

Was this helpful?

  1. Auth and permissions

Magic Links and codes

Magic Code auth

This Auth strategy creates and send a magic code to the email provided by the client

POST /auth/magic-code/
{
  "email":"user@email.com"
}

GET /auth/magic-code/:email/:token

Magic link auth

This Auth strategy creates and send a magic link to the email provided by the client

POST /auth/magic-link/
{
  "email":"user@email.com"
}

GET /auth/magic-link/:token

GET /auth/magic-token/:token
module.exports={
  resources:{
    user:{
      auth:{
        magicLink:{
          // field to check in request and user document
          emailField: 'email',
          // where to store the magic links in the db
          collection: 'moser-magic-links',
          // max tokens actives allowed per user
          max: 3,
          // how many time the tokens will be active
          exp: 'in one day',
          // where to redirect if the user is not found
          redirectNotFound: null,
          // where to redirect if the token was already used
          redirectAlreadyUsed: null,
          // where to redirect on success
          redirectSuccess: null,
          // function to execute on verify
          doVerify: null,
          // function to execute on token generation          
          doGenerate: null,
          // function to execute on token retrieve
          doRetrieve: null,
          // email options as nodemailer sendMail function https://nodemailer.com/about/
          email: Object.assign({}, {
            from: 'email@email.com',
            text: (user, token, url) => `${url}`,
            html: (user, token, url) => `${url}`,
            subject: 'Hey! use this link to login in our app',
          }),

          }
        }
      }
    }
  }

}
PreviousLocal authenticationNextServer description

Last updated 6 years ago

Was this helpful?