Skip to content

successfulAuthentication()

successfulAuthentication(user: TokenableUser, context: RouteContext) => Promise<SuccessfulAuthentication>

This function returns the user metadata along with the JWT token used to authenticate. It can be used to implement alternative signing in methods such as OAuth as ilustrated by these examples:

typescript
type TokenableUser = Pick<User,
  | '_id'
  | 'name'
  | 'email'
  | 'roles'
  | 'active'
  | 'picture'
>

type SuccessfulAuthentication = {
  user: TokenableUser
  token: TokenRecipient
}

Example

typescript
const { error, result: user } = await authenticate(payload)
if( error ) {
  return Result.error(error)
}

return Result.result(successfulAuthentication(user, context))

Released under the MIT License.