message: fix(server): invites: updates local strategy to use invite during pre-finalisation cb
diff: @@ -5,7 +5,7 @@ const appRoot = require( 'app-root-path' )
  const debug = require( 'debug' )
  const { createUser, updateUser, findOrCreateUser, validatePasssword, getUserByEmail } = require( `${appRoot}/modules/core/services/users` )
  const { getServerInfo } = require( `${appRoot}/modules/core/services/generic` )
  -const { validateInvite } = require( `${appRoot}/modules/serverinvites/services` )
  +const { validateInvite, useInvite } = require( `${appRoot}/modules/serverinvites/services` )
  module.exports = async ( app, session, sessionAppId, finalizeAuth ) => {
  const strategy = {
  @@ -16,8 +16,6 @@ module.exports = async ( app, session, sessionAppId, finalizeAuth ) => {
  url: '/auth/local'
  }
  - const serverInfo = await getServerInfo()
  -
  app.post( '/auth/local/login', session, sessionAppId, async ( req, res, next ) => {
  try {
  let valid = await validatePasssword( { email: req.body.email, password: req.body.password } )
  @@ -40,6 +38,7 @@ module.exports = async ( app, session, sessionAppId, finalizeAuth ) => {
  }, finalizeAuth )
  app.post( '/auth/local/register', session, sessionAppId, async ( req, res, next ) => {
  + const serverInfo = await getServerInfo()
  try {
  if ( !req.body.password )
  @@ -49,13 +48,14 @@ module.exports = async ( app, session, sessionAppId, finalizeAuth ) => {
  if ( serverInfo.inviteOnly && !req.session.inviteId ) {
  throw new Error( 'This server is invite only. Please provide an invite id.' )
  -
  }
  if ( req.session.inviteId ) {
  const valid = await validateInvite( { id: req.session.inviteId, email: user.email } )
  if ( !valid )
  throw new Error( 'Invite email mismatch. Please use the original email the invite was sent to register.' )
  +
  + await useInvite( { id: req.session.inviteId, email: user.email } )
  }
  let userId = await createUser( user )
  