Implemented a simple authentication scheme with Firebase and Iron Session
This commit is contained in:
21
src/pages/api/logout.ts
Normal file
21
src/pages/api/logout.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import {NextApiRequest, NextApiResponse} from "next";
|
||||
import {getAuth, signOut} 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(logout, sessionOptions);
|
||||
|
||||
async function logout(req: NextApiRequest, res: NextApiResponse) {
|
||||
signOut(auth)
|
||||
.then(() => {
|
||||
req.session.destroy();
|
||||
res.status(200).json({ok: true});
|
||||
})
|
||||
.catch(() => {
|
||||
req.session.destroy();
|
||||
res.status(500).json({ok: false});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user