-
Notifications
You must be signed in to change notification settings - Fork 0
add some changes #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
add some changes #64
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,48 @@ | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
| import { requireAuth } from "@/lib/auth-utils"; | ||
| import { auth } from "@/lib/auth"; | ||
| import { headers } from "next/headers"; | ||
| import { prisma } from "@/lib/prisma"; | ||
|
|
||
| export async function DELETE( | ||
| request: NextRequest, | ||
| { params }: { params: { sessionId: string } }, | ||
| { params }: { params: Promise<{ sessionId: string }> } | ||
| ) { | ||
| try { | ||
| const session = await requireAuth(); | ||
| const session = await auth.api.getSession({ headers: await headers() }); | ||
|
|
||
| // For demo purposes, just return success | ||
| // In production, you'd revoke the specific session | ||
| if (!session) { | ||
| return NextResponse.json( | ||
| { error: "Unauthorized", success: false }, | ||
| { status: 401 } | ||
| ); | ||
| } | ||
| const currentToken = session.session.token; | ||
| const { sessionId } = await params; | ||
| const sessionToRevoke = await prisma.session.findUnique({ | ||
| where: { id: sessionId }, | ||
| }); | ||
|
|
||
| // Prevent revoking current session | ||
| if (sessionToRevoke?.token === currentToken) { | ||
| return NextResponse.json( | ||
| { error: "Cannot revoke current session" }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
Comment on lines
+21
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing existence check for the session to revoke. Same issue as in Additionally, consider adding 🔎 Proposed fix const { sessionId } = await params;
const sessionToRevoke = await prisma.session.findUnique({
- where: { id: sessionId },
+ where: { id: sessionId, userId: session.user.id },
});
+ if (!sessionToRevoke) {
+ return NextResponse.json(
+ { error: "Session not found" },
+ { status: 404 }
+ );
+ }
+
// Prevent revoking current session
- if (sessionToRevoke?.token === currentToken) {
+ if (sessionToRevoke.token === currentToken) {
return NextResponse.json(
{ error: "Cannot revoke current session" },
{ status: 400 }
);
}
-
- await prisma.session.delete({
- where: {
- id: sessionId,
- userId: session.user.id,
- },
- });
+
+ await prisma.session.delete({
+ where: { id: sessionId },
+ });
🤖 Prompt for AI Agents |
||
|
|
||
| await prisma.session.delete({ | ||
| where: { | ||
| id: sessionId, | ||
| userId: session.user.id, | ||
| }, | ||
| }); | ||
|
|
||
| return NextResponse.json({ message: "Session revoked successfully" }); | ||
| } catch (error) { | ||
| console.error("Session revoke error:", error); | ||
| return NextResponse.json( | ||
| { error: "Failed to revoke session" }, | ||
| { status: 500 }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Avoid
@ts-ignore— fix the underlying type mismatch instead.Using
@ts-ignoresuppresses TypeScript errors without resolving them, which defeats the purpose of having typed props. The mismatch likely stems fromparams.settings_tabbeing typed asstring(from nuqs) whileSettingsSidebarandSettingsContentexpectSettingsTab.Consider typing the nuqs schema to align with
SettingsTab:Or cast at the usage site with a type assertion rather than ignoring:
Also applies to: 39-40
🤖 Prompt for AI Agents