Skip to content

Commit 92f3cc5

Browse files
author
Rajat
committed
Trusted origin for better-auth
1 parent f1587cb commit 92f3cc5

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

apps/web/app/(with-contexts)/(with-layout)/logout/page.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,28 @@ import { LOGOUT, LOGOUT_MESSAGE } from "@ui-config/strings";
55
import { useContext } from "react";
66
import { ThemeContext } from "@components/contexts";
77
import { authClient } from "@/lib/auth-client";
8+
import { useToast } from "@courselit/components-library";
89

910
export default function ClientSide() {
1011
const { theme } = useContext(ThemeContext);
12+
const { toast } = useToast();
1113

1214
const handleLogout = async () => {
13-
await authClient.signOut({
15+
const { error } = await authClient.signOut({
1416
fetchOptions: {
1517
onSuccess: () => {
1618
window.location.href = "/login";
1719
},
1820
},
1921
});
22+
23+
if (error) {
24+
toast({
25+
title: "Error",
26+
description: error?.message,
27+
variant: "destructive",
28+
});
29+
}
2030
};
2131

2232
return (

apps/web/auth.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { responses } from "@/config/strings";
1010
import { mongodbAdapter } from "@/ba-multitenant-adapter";
1111
import { updateUserAfterCreationViaAuth } from "./graphql/users/logic";
1212
import UserModel from "@models/User";
13+
import { getBackendAddress } from "./app/actions";
1314

1415
const client = new MongoClient(process.env.DB_CONNECTION_STRING || "");
1516
const db = client.db();
@@ -88,6 +89,10 @@ const config: any = {
8889
},
8990
},
9091
},
92+
trustedOrigins: async (request: Request) => {
93+
const backendAddress = await getBackendAddress(request.headers);
94+
return [backendAddress];
95+
},
9196
};
9297

9398
if (process.env.SESSION_COOKIE_CACHE_MAX_AGE) {

apps/web/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
import "./.next/types/routes.d.ts";
3+
import "./.next/dev/types/routes.d.ts";
44

55
// NOTE: This file should not be edited
66
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

0 commit comments

Comments
 (0)