Created
December 18, 2019 21:17
-
-
Save minskmaz/6fa14cfaa34691fcdd1a3f68ca87d222 to your computer and use it in GitHub Desktop.
mithril - token authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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