mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
fixed a bit of css
This commit is contained in:
1 parent
623e5d60bf
commit
795d43e1a5
4 files changed
+534
-751
No files matched your search
@@ -0,0 +1,30 @@
|
|||||||
|
import NextAuth from 'next-auth';
|
||||||
|
import Providers from 'next-auth/providers';
|
||||||
|
|
||||||
|
export const authOptions = {
|
||||||
|
providers: [
|
||||||
|
Providers.GitHub({
|
||||||
|
clientId: process.env.GITHUB_CLIENT_ID,
|
||||||
|
clientSecret: process.env.GITHUB_CLIENT_SECRET,
|
||||||
|
}),
|
||||||
|
// Add other providers here (e.g., Google, Email, etc.)
|
||||||
|
],
|
||||||
|
secret: process.env.NEXTAUTH_SECRET, // Ensure this is set in your .env file
|
||||||
|
callbacks: {
|
||||||
|
async session(session, user) {
|
||||||
|
// Add custom session properties if needed
|
||||||
|
session.user.id = user.id;
|
||||||
|
session.user.role = user.role; // Example: Add role to session
|
||||||
|
return session;
|
||||||
|
},
|
||||||
|
async jwt(token, user) {
|
||||||
|
if (user) {
|
||||||
|
token.id = user.id;
|
||||||
|
token.role = user.role; // Example: Add role to token
|
||||||
|
}
|
||||||
|
return token;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default NextAuth(authOptions);
|
||||||
@@ -7,8 +7,16 @@ export async function POST(request) {
|
|||||||
try {
|
try {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
|
// Debugging: Log the session
|
||||||
|
console.log('Session:', session);
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
return Response.json({ success: false, error: 'Unauthorised-tc' }, { status: 401 });
|
return Response.json({ success: false, error: 'Unauthorised' }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the user is not an admin
|
||||||
|
if (session.user.role === 'admin') {
|
||||||
|
return Response.json({ success: false, error: 'Admins cannot create teams' }, { status: 403 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const { name, userId } = await request.json();
|
const { name, userId } = await request.json();
|
||||||
@@ -17,18 +25,13 @@ export async function POST(request) {
|
|||||||
return Response.json({ success: false, error: 'Team name is required' });
|
return Response.json({ success: false, error: 'Team name is required' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the requesting user matches the userId
|
|
||||||
if (session.user.id !== userId) {
|
|
||||||
return Response.json({ success: false, error: 'User ID mismatch' }, { status: 403 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate a unique team code (6 characters)
|
// Generate a unique team code (6 characters)
|
||||||
const teamCode = nanoid(6).toUpperCase();
|
const teamCode = nanoid(6).toUpperCase();
|
||||||
|
|
||||||
// Insert the new team
|
// Insert the new team
|
||||||
const result = await run(
|
const result = await run(
|
||||||
'INSERT INTO teams (name, code, created_by) VALUES (?, ?, ?)',
|
'INSERT INTO teams (name, code) VALUES (?, ?)',
|
||||||
[name, teamCode, userId]
|
[name, teamCode]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result || !result.lastID) {
|
if (!result || !result.lastID) {
|
||||||
|
|||||||
Binary file not shown.
Reference in new issue
Block a user