nextjs-discord-oauth icon indicating copy to clipboard operation
nextjs-discord-oauth copied to clipboard

Logout

Open AriaFantom opened this issue 4 years ago • 2 comments

Can u please help for the logout?

AriaFantom avatar Jan 03 '22 04:01 AriaFantom

Just make a api route to delete all cookies.

yehorovye avatar Jan 05 '22 22:01 yehorovye

If still needed, here is a solution

/api/logout.ts

import { NextApiRequest, NextApiResponse } from "next";
import { serialize } from "cookie";

// Get our environment variables
const { COOKIE_NAME } = process.env;

export default async (_: NextApiRequest, res: NextApiResponse) => {
	// remove cookie from request header
	res.setHeader("Set-Cookie", [
		serialize(COOKIE_NAME, "", {
			maxAge: -1,
			path: "/",
		}),
	]);

	res.writeHead(302, { Location: "/" });
	res.end();
};

ibadus avatar Jan 08 '22 09:01 ibadus