mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-06-28 06:34:15 +00:00
fix: log out issue
This commit is contained in:
parent
d5c619567a
commit
333c97bfca
3 changed files with 20 additions and 2 deletions
18
backend/src/app/api/auth/logout/route.ts
Normal file
18
backend/src/app/api/auth/logout/route.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { auth } from "@/lib/auth";
|
||||||
|
import { prisma } from "@/lib/prisma";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
const session = await auth();
|
||||||
|
|
||||||
|
if (session) {
|
||||||
|
await prisma.session.deleteMany({
|
||||||
|
where: { userId: Number(session?.user?.id) },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = NextResponse.redirect(process.env.NEXT_PUBLIC_FRONTEND_URL ?? "http://localhost:3000");
|
||||||
|
response.cookies.delete("next-auth.session-token");
|
||||||
|
response.cookies.delete("__Secure-next-auth.session-token");
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
@ -90,7 +90,7 @@ export default function Header() {
|
||||||
</li>
|
</li>
|
||||||
<li title="Logout">
|
<li title="Logout">
|
||||||
<Link
|
<Link
|
||||||
to={`${import.meta.env.VITE_API_URL}/api/auth/signout`}
|
to={`${import.meta.env.VITE_API_URL}/api/auth/logout`}
|
||||||
aria-label="Log Out"
|
aria-label="Log Out"
|
||||||
className="pill button p-2! aspect-square h-full"
|
className="pill button p-2! aspect-square h-full"
|
||||||
data-tooltip="Log Out"
|
data-tooltip="Log Out"
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ export default function ProfileLayout() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(`${import.meta.env.VITE_API_URL}/api/profile/${userId}/info`)
|
fetch(`${import.meta.env.VITE_API_URL}/api/profile/${userId}/info`, { cache: "no-store" })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res.ok) throw new Error("Failed to fetch profile");
|
if (!res.ok) throw new Error("Failed to fetch profile");
|
||||||
return res.json();
|
return res.json();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue