Skip to content

Instantly share code, notes, and snippets.

@polluterofminds
Created January 12, 2021 17:41
Show Gist options
  • Save polluterofminds/3d7dc3f76f2047f49ef6a6e15af6d3ce to your computer and use it in GitHub Desktop.
Save polluterofminds/3d7dc3f76f2047f49ef6a6e15af6d3ce to your computer and use it in GitHub Desktop.
Login
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