chore: migrate /auth/logout (#18901)
* migrate /auth/verify-email page * update middleware * migrate /auth/logout page
This commit is contained in:
1 parent
2f9beed450
commit
ed3579c5c7
5 files changed
+13
-51
No files matched your search
+3
-8
@@ -1,6 +1,5 @@
|
||||
import type { PageProps } from "app/_types";
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
import { WithLayout } from "app/layoutHOC";
|
||||
import { cookies, headers } from "next/headers";
|
||||
|
||||
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
|
||||
@@ -20,13 +19,9 @@ const Page = async ({ params, searchParams }: PageProps) => {
|
||||
// cookie will be cleared in `/apps/web/middleware.ts`
|
||||
const h = headers();
|
||||
const context = buildLegacyCtx(h, cookies(), params, searchParams);
|
||||
const ssr = await ssrInit(context);
|
||||
const props = {
|
||||
trpcState: ssr.dehydrate(),
|
||||
query: context.query,
|
||||
};
|
||||
await ssrInit(context);
|
||||
|
||||
return <Logout {...props} />;
|
||||
return <Logout query={context.query} />;
|
||||
};
|
||||
|
||||
export default WithLayout({ getLayout: null, ServerPage: Page })<"P">;
|
||||
export default Page;
|
||||
@@ -1,6 +1,5 @@
|
||||
import { get } from "@vercel/edge-config";
|
||||
import { collectEvents } from "next-collect/server";
|
||||
import { cookies } from "next/headers";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
@@ -73,13 +72,6 @@ const middleware = async (req: NextRequest): Promise<NextResponse<unknown>> => {
|
||||
}
|
||||
}
|
||||
|
||||
if (url.pathname.startsWith("/future/auth/logout")) {
|
||||
cookies().set("next-auth.session-token", "", {
|
||||
path: "/",
|
||||
expires: new Date(0),
|
||||
});
|
||||
}
|
||||
|
||||
requestHeaders.set("x-pathname", url.pathname);
|
||||
|
||||
const locale = await getLocale(req);
|
||||
@@ -92,6 +84,10 @@ const middleware = async (req: NextRequest): Promise<NextResponse<unknown>> => {
|
||||
},
|
||||
});
|
||||
|
||||
if (url.pathname.startsWith("/auth/logout")) {
|
||||
res.cookies.delete("next-auth.session-token");
|
||||
}
|
||||
|
||||
return responseWithHeaders({ url, res, req });
|
||||
};
|
||||
|
||||
@@ -159,6 +155,7 @@ export const config = {
|
||||
"/api/trpc/:path*",
|
||||
"/login",
|
||||
"/auth/login",
|
||||
"/auth/logout",
|
||||
"/auth/error",
|
||||
"/auth/signin",
|
||||
"/auth/oauth2/authorize",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { signOut, useSession } from "next-auth/react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import type { ParsedUrlQuery } from "querystring";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { WEBSITE_URL } from "@calcom/lib/constants";
|
||||
@@ -9,13 +10,11 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Button } from "@calcom/ui";
|
||||
import { Icon } from "@calcom/ui";
|
||||
|
||||
import type { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
|
||||
import AuthContainer from "@components/ui/AuthContainer";
|
||||
|
||||
import type { getServerSideProps } from "@server/lib/auth/logout/getServerSideProps";
|
||||
|
||||
export type PageProps = inferSSRProps<typeof getServerSideProps>;
|
||||
export type PageProps = {
|
||||
query: ParsedUrlQuery;
|
||||
};
|
||||
|
||||
export function Logout(props: PageProps) {
|
||||
const [btnLoading, setBtnLoading] = useState<boolean>(false);
|
||||
@@ -42,7 +41,7 @@ export function Logout(props: PageProps) {
|
||||
};
|
||||
|
||||
return (
|
||||
<AuthContainer title={t("logged_out")} description={t("youve_been_logged_out")} showLogo>
|
||||
<AuthContainer title={t("logged_out")} description={t("youve_been_logged_out")} showLogo isAppDir>
|
||||
<div className="mb-4">
|
||||
<div className="bg-success mx-auto flex h-12 w-12 items-center justify-center rounded-full">
|
||||
<Icon name="check" className="h-6 w-6 text-green-600" />
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import PageWrapper from "@components/PageWrapper";
|
||||
|
||||
import type { PageProps } from "~/auth/logout-view";
|
||||
import Logout from "~/auth/logout-view";
|
||||
|
||||
const Page = (props: PageProps) => <Logout {...props} />;
|
||||
Page.PageWrapper = PageWrapper;
|
||||
|
||||
export default Page;
|
||||
export { getServerSideProps } from "@server/lib/auth/logout/getServerSideProps";
|
||||
@@ -1,19 +0,0 @@
|
||||
import type { GetServerSidePropsContext } from "next";
|
||||
|
||||
import { ssrInit } from "@server/lib/ssr";
|
||||
|
||||
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
const ssr = await ssrInit(context);
|
||||
// Deleting old cookie manually, remove this code after all existing cookies have expired
|
||||
context.res?.setHeader(
|
||||
"Set-Cookie",
|
||||
"next-auth.session-token=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"
|
||||
);
|
||||
|
||||
return {
|
||||
props: {
|
||||
trpcState: ssr.dehydrate(),
|
||||
query: context.query,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user