Created
January 12, 2021 17:41
-
-
Save polluterofminds/3d7dc3f76f2047f49ef6a6e15af6d3ce to your computer and use it in GitHub Desktop.
Login
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
import { checkSubscriptions, createJWT, sendEmail } from "./subscribe"; | |
export default async (req, res) => { | |
try { | |
// Check for existing subscription | |
const existingSubscription = await checkSubscriptions(req.body.email); | |
if (!existingSubscription) { | |
return res.status(400).send("User is not subscribed"); | |
} | |
// Create the JWT | |
const token = await createJWT(req.body.email); | |
// send email | |
await sendEmail(req.body.email, token); | |
res.status(200).send("Success"); | |
} catch (error) { | |
console.log(error); | |
res.status(500).send("Server error"); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment