Created
October 22, 2022 21:25
-
-
Save itwasmattgregg/69e5e723305062e02a422ebb6d42476f to your computer and use it in GitHub Desktop.
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
import { withSessionRoute } from '@utils/session'; | |
export default withSessionRoute(async (req, res) => { | |
const { password } = await req.body; | |
try { | |
if (password === process.env.PASSWORD) { | |
const user = { isLoggedIn: true }; | |
req.session.user = user; | |
await req.session.save(); | |
res.json(user); | |
} else { | |
const user = { isLoggedIn: false }; | |
res.json(user); | |
} | |
} catch (error) { | |
const { response: fetchResponse } = error; | |
res.status(fetchResponse?.status || 500).json(error.data); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment