Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post('/login', (req,res) =>{
- if(!req.body.username || !req.body.password){
- //check to make sure the body has both a password and a username
- res.status(400).send('Missing info!')
- }
- //Imagine this is our database.
- let users = {
- peter:{
- username:"spiderman",
- password:"My Spider-Sense is tingling." }
- }
- //simple check to make sure the RIGHT username is sent with a correct password.
- //Check to see if we have that user
- if( users[req.body.username] ){
- //Check the password sent against the one on our user
- if( users[req.body.username].password == users[req.body.username].password ){
- //Make and sign our token
- let token = jwt.sign(users[req.body.username], secret)
- //Send a response with a success status with whatever information we would like to send to the client
- return res.status(200).json({token:token, info:"Response success and payload returned"});
- }
- }else{
- //The password didnt match so we send back a message.
- return res.status(400).send('incorrect info!');
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement