11.4.3 • Published 2 months ago

fl-auth-server v11.4.3

Weekly downloads
8
License
MIT
Repository
github
Last release
2 months ago

Server side of fl-auth-*, an auth package for FounderLab apps

Usage (server) - values shown are defaults:

import { configure as configureAuth, loggedIn } from 'fl-auth-server'

app = express()                       // Provide your express app
configureAuth({
  app,

  User: require('./models/user'),     // Give fl-auth-server another User model to use if you have a custom one

  middleware: {
    initialize: true,                 // enable passport middleware 
    session: true,                    // (don't change these)
  },

  paths: {
    login: '/login',                  // Route to log someone in
    register: '/register',            // Route to register a new user
    logout: '/logout',                // Route to log someone out
    resetRequest: '/reset-request',  // Route to request a password reset email be sent
                                      // must provide `email` as a param in the body, e.g. {email: 'a@example.com'} 
    reset: '/reset',                  // Route that a user will visit to perform their password reset. 
                                      // Requires `resetToken` as a param. This token is generated by the reset-request 
                                      // and should be passed through via the email you sent them from their reset-request.
    success: '/',                     // Go here when a user logs in or registers 
                                      // (if there's no other location specified) <- This isn't implemented yet
  },
  
  /*
   *  A facebook oath route will be created at the `paths.redirect` url
   *  When signing in users with facebook open this url, they will be redirected to facebook for authentication and back
   *  Your User model should have `facebookId` and `facebookAccessToken` fields where their facebook info will be saved
   *  
   */
  facebook: {                         
    clientId: ,                       // Your facebook app id (required)
    clientSecret: ,                   // Your facebook app secret (required)

    url: process.env.URL,
    paths: {
      redirect: '/auth/facebook',
      callback: '/auth/facebook/callback',
    },
    scope: ['email'],
    profileFields: ['id', 'displayName', 'email'],
  },
  
  /*
   *  Same deal for linkedin
   */
  facebook: {                         
    clientId: ,                       // Your facebook app id (required)
    clientSecret: ,                   // Your facebook app secret (required)

    url: process.env.URL,
    paths: {
      redirect: '/auth/linkedin',
      callback: '/auth/linkedin/callback',
    },
    scope: ['r_emailaddress', 'r_basicprofile'],
    profileFields: ['first-name', 'last-name', 'email-address', 'formatted-name', 'location', 'industry', 'summary', 'specialties', 'positions', 'picture-url', 'public-profile-url'],
  },
  
  login: {                          
    usernameField: 'email',                                // The login/register strategies look for these properties on the request body
    passwordField: 'password',                             //
    badRequestMessage: 'Missing credentials',             // If username or password is missing this is sent
    resetTokenExpiresMs: 1000 * 60 * 60 * 24 * 7,        // Reset tokens expire in 7 days by default
    extraRegisterParams: ['type'],                        // Extra fields to be plucked from the body of a POST to /register that will be saved on the user model. Fields not in this whitelist (other than usernameField/passwordField) are ignored
  },

  // You need to override this with a function that sends this user an email with a link to the reset page, 
  // with a query param containing this resetToken 
  // e.g. <a href="https://example.com/reset?resetToken=${user.get('resetToken')}>Reset your password here</a>
  sendResetEmail: ({user, req}, callback) => {
    console.log('[fl-auth] sendResetEmail not configured. No password reset email will be sent. Reset token:', user.get('email'), user.get('resetToken'))
    callback()
  },

  sendConfirmationEmail: (user, callback) => {
    // same deal with this. Send an email with a link to confirm the email
    // e.g.
    const email = user.get('email')
    const query = querystring.stringify({email, token: user.get('emailConfirmationToken')})
    const message = `${appConfig.url}/confirm-email?${query}`
    console.log('Sending emailConfirmationToken email', email, user.get('emailConfirmationToken'), message)
    sendMail({to: email, subject: `Confirm your email for ${appConfig.url}`, text: message}, callback)
  }

})
11.4.3

2 months ago

11.4.2

2 months ago

11.4.0

6 months ago

11.0.0

12 months ago

10.0.0

1 year ago

9.0.3

2 years ago

9.0.2

2 years ago

9.0.1

2 years ago

9.0.0

2 years ago

9.0.0-rc.6

2 years ago

9.0.0-rc.3

2 years ago

9.0.0-rc.4

2 years ago

9.0.0-rc.2

2 years ago

8.0.12

2 years ago

7.8.0

2 years ago

8.0.8

2 years ago

8.0.7

2 years ago

7.6.23

2 years ago

7.6.21

3 years ago

7.6.17

3 years ago

7.4.22

3 years ago

7.5.2

3 years ago

7.5.1

3 years ago

7.5.0

3 years ago

7.4.21

3 years ago

7.4.20

3 years ago

7.4.12

4 years ago

7.4.11

4 years ago

7.4.6

4 years ago

7.3.14

4 years ago

7.3.11

4 years ago

7.3.10

4 years ago

7.3.9

4 years ago

7.3.8

4 years ago

7.3.3

4 years ago

7.3.0

4 years ago

7.2.7

4 years ago

7.1.1

4 years ago

7.0.22

5 years ago

7.0.1

5 years ago

7.0.0

5 years ago

6.18.0

5 years ago

6.15.1

5 years ago

6.14.9

5 years ago

6.14.8

5 years ago

6.14.7

5 years ago

6.14.6

5 years ago

6.14.0

5 years ago

6.13.1

5 years ago

6.13.0

5 years ago

6.12.7

5 years ago

6.12.6

5 years ago

6.12.1

5 years ago

6.11.2

5 years ago

6.11.1

5 years ago

6.11.0

5 years ago

6.10.4

5 years ago

6.10.3

5 years ago

6.8.0

5 years ago

6.7.19

5 years ago

6.7.18

5 years ago

6.7.17

5 years ago

6.7.15

5 years ago

6.7.13

5 years ago

6.7.11

6 years ago

6.7.10

6 years ago

6.7.8

6 years ago

6.7.7

6 years ago

6.7.6

6 years ago

6.7.5

6 years ago

6.7.4

6 years ago

6.7.0

6 years ago

6.4.1

6 years ago

6.3.1

6 years ago

6.2.3

6 years ago

6.1.10

6 years ago

6.1.9

6 years ago

6.1.8

6 years ago

6.1.1

6 years ago

6.1.0

6 years ago

6.0.4

6 years ago

6.0.3

6 years ago

6.0.1

6 years ago

6.0.0

6 years ago

5.0.3

6 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

7 years ago

1.0.0-alpha.7

7 years ago

1.0.0-alpha.6

7 years ago

1.0.0-alpha.5

7 years ago

1.0.0-alpha.4

7 years ago

1.0.0-alpha.3

7 years ago

1.0.0-alpha.2

7 years ago

1.0.0-alpha.1

7 years ago

0.16.2

7 years ago

0.16.1

7 years ago

0.16.0

7 years ago

0.15.3

7 years ago

0.15.2

7 years ago

0.15.1

7 years ago

0.15.0

7 years ago

0.14.1

7 years ago

0.14.0

7 years ago

0.13.9

7 years ago

0.13.8

7 years ago

0.13.7

7 years ago

0.13.6

7 years ago

0.13.5

8 years ago

0.13.4

8 years ago

0.13.3

8 years ago

0.13.2

8 years ago

0.13.1

8 years ago

0.13.0

8 years ago

0.12.3

8 years ago

0.12.2

8 years ago

0.12.1

8 years ago

0.12.0

8 years ago

0.11.4

8 years ago

0.11.3

8 years ago

0.11.2

8 years ago

0.11.1

8 years ago

0.11.0

8 years ago

0.10.4

8 years ago

0.10.3

8 years ago

0.10.2

8 years ago

0.10.1

8 years ago

0.10.0

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago