solve mail backend 4
This commit is contained in:
parent
a3510861c5
commit
2c3a4ffca6
@ -1,5 +1,6 @@
|
||||
import NextAuth, { NextAuthOptions } from "next-auth";
|
||||
import KeycloakProvider from "next-auth/providers/keycloak";
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
declare module "next-auth" {
|
||||
interface Session {
|
||||
@ -94,6 +95,29 @@ export const authOptions: NextAuthOptions = {
|
||||
}
|
||||
},
|
||||
callbacks: {
|
||||
async signIn({ user, account, profile }) {
|
||||
if (!user.email) return false;
|
||||
|
||||
try {
|
||||
// Create or update user in local database
|
||||
await prisma.user.upsert({
|
||||
where: { id: user.id },
|
||||
update: {
|
||||
email: user.email,
|
||||
password: '', // We don't store password for Keycloak users
|
||||
},
|
||||
create: {
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
password: '', // We don't store password for Keycloak users
|
||||
},
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error creating/updating user:', error);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
async jwt({ token, account, profile }) {
|
||||
if (account && profile) {
|
||||
token.accessToken = account.access_token ?? '';
|
||||
|
||||
@ -527,8 +527,8 @@ export default function MailPage() {
|
||||
if (!response.ok) {
|
||||
// No credentials found, redirect to login
|
||||
router.push("/mail/login");
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// We have credentials, fetch mails
|
||||
fetchMails();
|
||||
} catch (err) {
|
||||
@ -552,6 +552,6 @@ export default function MailPage() {
|
||||
<div className="flex flex-col h-full">
|
||||
<MailToolbar />
|
||||
<MailList mails={mails} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user