Skip to content

Instantly share code, notes, and snippets.

@minskmaz
Created December 18, 2019 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minskmaz/6fa14cfaa34691fcdd1a3f68ca87d222 to your computer and use it in GitHub Desktop.
Save minskmaz/6fa14cfaa34691fcdd1a3f68ca87d222 to your computer and use it in GitHub Desktop.
mithril - token authentication
if( tokenInHash ){
// User has just been authenticated!
m.route( body, '/profile', routes.authenticated )
}
else if( localToken ){
// We already have a token, could still be valid
m.route( body, '/login', routes.waiting )
validate( localToken ).then(
success => m.route( body, '/profile', routes.authenticated ),
failure => m.route( body, '/login', routes.lockedOut )
)
}
else {
m.route( body, '/signup', routes.lockedOut )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment