minor changes

This commit is contained in:
daniel31x13 2023-11-19 08:38:05 -05:00
parent eb78fb71d9
commit 9938d21499
3 changed files with 13 additions and 10 deletions

View File

@ -29,5 +29,5 @@ POSTGRES_PASSWORD=
# Keycloak # Keycloak
NEXT_PUBLIC_KEYCLOAK_ENABLED= NEXT_PUBLIC_KEYCLOAK_ENABLED=
KEYCLOAK_ISSUER= KEYCLOAK_ISSUER=
KEYCLOAK_CLIENT= KEYCLOAK_CLIENT_ID=
KEYCLOAK_CLIENT_SECRET= KEYCLOAK_CLIENT_SECRET=

View File

@ -22,7 +22,10 @@ export default async function deleteUserById(
} }
// Then, we check if the provided password matches the one stored in the database // Then, we check if the provided password matches the one stored in the database
const isPasswordValid = bcrypt.compareSync(body.password, user.password || ""); const isPasswordValid = bcrypt.compareSync(
body.password,
user.password || ""
);
if (!isPasswordValid) { if (!isPasswordValid) {
return { return {

View File

@ -9,13 +9,12 @@ import { Adapter } from "next-auth/adapters";
import sendVerificationRequest from "@/lib/api/sendVerificationRequest"; import sendVerificationRequest from "@/lib/api/sendVerificationRequest";
import { Provider } from "next-auth/providers"; import { Provider } from "next-auth/providers";
import verifySubscription from "@/lib/api/verifySubscription"; import verifySubscription from "@/lib/api/verifySubscription";
import KeycloakProvider from 'next-auth/providers/keycloak'; import KeycloakProvider from "next-auth/providers/keycloak";
const emailEnabled = const emailEnabled =
process.env.EMAIL_FROM && process.env.EMAIL_SERVER ? true : false; process.env.EMAIL_FROM && process.env.EMAIL_SERVER ? true : false;
const keycloakEnabled = const keycloakEnabled = process.env.NEXT_PUBLIC_KEYCLOAK_ENABLED === "true";
!!process.env.NEXT_PUBLIC_KEYCLOAK_ENABLED;
const adapter = PrismaAdapter(prisma); const adapter = PrismaAdapter(prisma);
@ -81,8 +80,8 @@ if (emailEnabled) {
if (keycloakEnabled) { if (keycloakEnabled) {
providers.push( providers.push(
KeycloakProvider({ KeycloakProvider({
id: 'keycloak', id: "keycloak",
name: 'Keycloak', name: "Keycloak",
clientId: process.env.KEYCLOAK_CLIENT_ID!, clientId: process.env.KEYCLOAK_CLIENT_ID!,
clientSecret: process.env.KEYCLOAK_CLIENT_SECRET!, clientSecret: process.env.KEYCLOAK_CLIENT_SECRET!,
issuer: process.env.KEYCLOAK_ISSUER, issuer: process.env.KEYCLOAK_ISSUER,
@ -95,11 +94,11 @@ if (keycloakEnabled) {
image: profile.picture, image: profile.picture,
}; };
}, },
}), })
); );
const _linkAccount = adapter.linkAccount; const _linkAccount = adapter.linkAccount;
adapter.linkAccount = (account) => { adapter.linkAccount = (account) => {
const { 'not-before-policy': _, refresh_expires_in, ...data } = account; const { "not-before-policy": _, refresh_expires_in, ...data } = account;
return _linkAccount ? _linkAccount(data) : undefined; return _linkAccount ? _linkAccount(data) : undefined;
}; };
} }
@ -118,7 +117,8 @@ export const authOptions: AuthOptions = {
callbacks: { callbacks: {
async jwt({ token, trigger, user }) { async jwt({ token, trigger, user }) {
token.sub = token.sub ? Number(token.sub) : undefined; token.sub = token.sub ? Number(token.sub) : undefined;
if (trigger === "signIn" || trigger === "signUp") token.id = user?.id as number; if (trigger === "signIn" || trigger === "signUp")
token.id = user?.id as number;
return token; return token;
}, },