Neah version calendar fix 3 debuger ???? ??
This commit is contained in:
parent
8d91a350c8
commit
f14bfc1203
64
lib/auth.ts
64
lib/auth.ts
@ -1,51 +1,28 @@
|
|||||||
import { NextAuthOptions } from 'next-auth';
|
import { NextAuthOptions } from 'next-auth';
|
||||||
import CredentialsProvider from 'next-auth/providers/credentials';
|
import KeycloakProvider from 'next-auth/providers/keycloak';
|
||||||
import { PrismaClient } from '@prisma/client';
|
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
declare module 'next-auth' {
|
declare module 'next-auth' {
|
||||||
interface User {
|
interface User {
|
||||||
id: string;
|
id: string;
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
name?: string;
|
||||||
|
role: string[];
|
||||||
}
|
}
|
||||||
interface Session {
|
interface Session {
|
||||||
user: User;
|
user: User;
|
||||||
}
|
}
|
||||||
|
interface Profile {
|
||||||
|
roles?: string[];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const authOptions: NextAuthOptions = {
|
export const authOptions: NextAuthOptions = {
|
||||||
providers: [
|
providers: [
|
||||||
CredentialsProvider({
|
KeycloakProvider({
|
||||||
name: 'Credentials',
|
clientId: process.env.KEYCLOAK_CLIENT_ID!,
|
||||||
credentials: {
|
clientSecret: process.env.KEYCLOAK_CLIENT_SECRET!,
|
||||||
email: { label: 'Email', type: 'email' },
|
issuer: process.env.KEYCLOAK_ISSUER,
|
||||||
password: { label: 'Password', type: 'password' }
|
}),
|
||||||
},
|
|
||||||
async authorize(credentials) {
|
|
||||||
if (!credentials?.email || !credentials?.password) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find user in database
|
|
||||||
const user = await prisma.user.findUnique({
|
|
||||||
where: { email: credentials.email },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Here you would typically verify the password
|
|
||||||
// For now, we'll just return the user
|
|
||||||
return {
|
|
||||||
id: user.id,
|
|
||||||
email: user.email,
|
|
||||||
password: user.password,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
})
|
|
||||||
],
|
],
|
||||||
session: {
|
session: {
|
||||||
strategy: 'jwt',
|
strategy: 'jwt',
|
||||||
@ -54,11 +31,13 @@ export const authOptions: NextAuthOptions = {
|
|||||||
signIn: '/login',
|
signIn: '/login',
|
||||||
},
|
},
|
||||||
callbacks: {
|
callbacks: {
|
||||||
async jwt({ token, user }) {
|
async jwt({ token, account, profile }) {
|
||||||
if (user) {
|
if (account && profile) {
|
||||||
token.id = user.id;
|
// Store the Keycloak user ID
|
||||||
token.email = user.email;
|
token.id = profile.sub;
|
||||||
token.password = user.password;
|
token.email = profile.email || '';
|
||||||
|
token.name = profile.name;
|
||||||
|
token.role = profile.roles || ['user'];
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
},
|
},
|
||||||
@ -66,9 +45,10 @@ export const authOptions: NextAuthOptions = {
|
|||||||
if (token) {
|
if (token) {
|
||||||
session.user.id = token.id as string;
|
session.user.id = token.id as string;
|
||||||
session.user.email = token.email as string;
|
session.user.email = token.email as string;
|
||||||
session.user.password = token.password as string;
|
session.user.name = token.name as string;
|
||||||
|
session.user.role = token.role as string[];
|
||||||
}
|
}
|
||||||
return session;
|
return session;
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
@ -11,16 +11,6 @@ datasource db {
|
|||||||
url = env("DATABASE_URL")
|
url = env("DATABASE_URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
model User {
|
|
||||||
id String @id @default(uuid())
|
|
||||||
email String @unique
|
|
||||||
password String
|
|
||||||
createdAt DateTime @default(now())
|
|
||||||
updatedAt DateTime @updatedAt
|
|
||||||
calendars Calendar[]
|
|
||||||
events Event[]
|
|
||||||
}
|
|
||||||
|
|
||||||
model Calendar {
|
model Calendar {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
name String
|
name String
|
||||||
@ -30,7 +20,6 @@ model Calendar {
|
|||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
events Event[]
|
events Event[]
|
||||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
||||||
|
|
||||||
@@index([userId])
|
@@index([userId])
|
||||||
}
|
}
|
||||||
@ -48,7 +37,6 @@ model Event {
|
|||||||
userId String
|
userId String
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
||||||
|
|
||||||
@@index([calendarId])
|
@@index([calendarId])
|
||||||
@@index([userId])
|
@@index([userId])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user