Skip to content
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

Codespace fuzzy spoon r4rqjv6jw974c54p5 #58

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions .env.example

This file was deleted.

21 changes: 0 additions & 21 deletions LICENSE.md

This file was deleted.

128 changes: 0 additions & 128 deletions README.md

This file was deleted.

78 changes: 77 additions & 1 deletion app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1 +1,77 @@
export { GET, POST } from "@/auth"
import NextAuth,{ DefaultSession } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import { PrismaAdapter } from "@auth/prisma-adapter";
import { prisma } from "@/lib/db";
import { UserRole } from "@prisma/client";

declare module "next-auth" {
interface Session {
user: {
id: string;
role: UserRole;
} & DefaultSession["user"];
}

interface User {
role: UserRole;
}
}

declare module "next-auth/jwt" {
interface JWT {
id: string;
role: UserRole;
}
}

export const authOptions = {
adapter: PrismaAdapter(prisma),
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: { label: "Email", type: "text", placeholder: "[email protected]" },
password: { label: "Password", type: "password" }
},
async authorize(credentials) {
// Mocked user for testing
if (credentials?.email === "[email protected]" && credentials?.password === "test") {
return {
id: "1",
name: "Test User",
email: "[email protected]",
role: UserRole.USER,
image: null,
};
}
return null;
}
})
],
session: {
strategy: "jwt",
},
pages: {
signIn: "/signin",
},
callbacks: {
async jwt({ token, user }: { token: any; user: any }) {
if (user) {
token.id = user.id;
token.role = user.role;
}
return token;
},
async session({ session, token }: { session: any; token: any }) {
if (session.user) {
session.user.id = token.id;
session.user.role = token.role;
}
return session;
},
},
};

const handler = authOptions;

export { handler as GET, handler as POST };
34 changes: 10 additions & 24 deletions app/api/user/route.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
import { auth } from "@/auth";

import { prisma } from "@/lib/db";

export const DELETE = auth(async (req) => {
if (!req.auth) {
return new Response("Not authenticated", { status: 401 });
}

const currentUser = req.auth.user;
if (!currentUser) {
return new Response("Invalid user", { status: 401 });
}

try {
await prisma.user.delete({
where: {
id: currentUser.id,
},
});
} catch (error) {
return new Response("Internal server error", { status: 500 });
import { NextResponse } from 'next/server';
import { getCurrentUser } from "@/lib/session";

export async function GET() {
const user = await getCurrentUser();

if (!user) {
return NextResponse.json({ error: 'User not found' }, { status: 404 });
}

return new Response("User deleted successfully!", { status: 200 });
});
return NextResponse.json(user);
}
20 changes: 0 additions & 20 deletions auth.config.ts

This file was deleted.

Loading