mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
redo of entire app
This commit is contained in:
1 parent
7dee4879a7
commit
093dd7ea9e
45 files changed
+686
-5659
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import NextAuth from 'next-auth';
|
||||
import Providers from 'next-auth/providers';
|
||||
import bcrypt from 'bcryptjs';
|
||||
import { query } from '../../../lib/db';
|
||||
|
||||
export default NextAuth({
|
||||
providers: [
|
||||
Providers.Credentials({
|
||||
name: 'Credentials',
|
||||
credentials: {
|
||||
username: { label: 'Username', type: 'text' },
|
||||
password: { label: 'Password', type: 'password' },
|
||||
},
|
||||
authorize: async (credentials) => {
|
||||
const user = await query('SELECT * FROM users WHERE username = ?', [credentials.username]);
|
||||
if (user && bcrypt.compareSync(credentials.password, user.password)) {
|
||||
return { id: user.id, name: user.username, role: user.role };
|
||||
}
|
||||
return null;
|
||||
},
|
||||
}),
|
||||
],
|
||||
callbacks: {
|
||||
jwt: async (token, user) => {
|
||||
if (user) {
|
||||
token.role = user.role;
|
||||
}
|
||||
return token;
|
||||
},
|
||||
session: async (session, token) => {
|
||||
session.user.role = token.role;
|
||||
return session;
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
signIn: '/login', // Redirect to the login page
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import { query } from '../../../lib/db';
|
||||
|
||||
export async function POST(request) {
|
||||
const { clueId, teamId } = await request.json();
|
||||
|
||||
await query('UPDATE clues SET found = TRUE WHERE id = ? AND team_id = ?', [
|
||||
clueId,
|
||||
teamId,
|
||||
]);
|
||||
|
||||
return Response.json({ message: 'Clue marked as found' });
|
||||
}
|
||||
Reference in new issue
Block a user