Made it so users have to verify their e-mail starting to use the application
This commit is contained in:
24
src/pages/api/reset/sendVerification.ts
Normal file
24
src/pages/api/reset/sendVerification.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {NextApiRequest, NextApiResponse} from "next";
|
||||
import {getAuth, sendSignInLinkToEmail, User} from "firebase/auth";
|
||||
import {app} from "@/firebase";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
|
||||
const auth = getAuth(app);
|
||||
|
||||
export default withIronSessionApiRoute(sendVerification, sessionOptions);
|
||||
|
||||
async function sendVerification(req: NextApiRequest, res: NextApiResponse) {
|
||||
console.log(auth.currentUser);
|
||||
if (req.session.user) {
|
||||
sendSignInLinkToEmail(auth, req.session.user.email, {
|
||||
url: "https://encoach.com/",
|
||||
handleCodeInApp: true,
|
||||
})
|
||||
.then(() => res.status(200).json({ok: true}))
|
||||
.catch((e) => {
|
||||
console.log(e);
|
||||
res.status(404).json({ok: false});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user