Skip to content

Instantly share code, notes, and snippets.

@eblind39
Created August 14, 2022 02:21
Show Gist options
  • Save eblind39/d7c323c9415f8123d24c5d968a2e8086 to your computer and use it in GitHub Desktop.
Save eblind39/d7c323c9415f8123d24c5d968a2e8086 to your computer and use it in GitHub Desktop.
Mock Service Worker - get values from request body
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