Skip to content

Commit

Permalink
chore: migrate /auth/logout (#18901)
Browse files Browse the repository at this point in the history
* migrate /auth/verify-email page

* update middleware

* migrate /auth/logout page
  • Loading branch information
hbjORbj authored Jan 27, 2025
1 parent 2f9beed commit ed3579c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
13 changes: 5 additions & 8 deletions apps/web/middleware.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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);
Expand All @@ -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 });
};

Expand Down Expand Up @@ -159,6 +155,7 @@ export const config = {
"/api/trpc/:path*",
"/login",
"/auth/login",
"/auth/logout",
"/auth/error",
"/auth/signin",
"/auth/oauth2/authorize",
Expand Down
11 changes: 5 additions & 6 deletions apps/web/modules/auth/logout-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

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";
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);
Expand All @@ -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" />
Expand Down
10 changes: 0 additions & 10 deletions apps/web/pages/auth/logout.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions apps/web/server/lib/auth/logout/getServerSideProps.tsx

This file was deleted.

0 comments on commit ed3579c

Please sign in to comment.