Created
August 14, 2022 02:21
-
-
Save eblind39/d7c323c9415f8123d24c5d968a2e8086 to your computer and use it in GitHub Desktop.
Mock Service Worker - get values from request body
This file contains hidden or 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
server.use( | |
rest.post('/login', (req, res, ctx) => { | |
const {email, password} = req.body as DefaultBodyType & { | |
email: string | |
password: string | |
} | |
if ( | |
email === '[email protected]' && | |
password === 'Aa12345678$' | |
) { | |
return res( | |
ctx.status(HTTPStatusCodes.UNAUTHORIZED), | |
ctx.json({ | |
message: 'The email or password are not correct', | |
}), | |
) | |
} | |
return res( | |
ctx.status(HTTPStatusCodes.OK_STATUS), | |
ctx.json({message: 'Ok'}), | |
) | |
}), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment