1
0
Fork 0

fix(nextauth): eslint errors

This commit is contained in:
Vojtěch Mareš 2023-09-03 11:24:08 +02:00
parent 60d455c938
commit e54c69f216
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D

View file

@ -6,9 +6,7 @@ import {
type DefaultSession,
} from "next-auth";
import KeycloakProvider from "next-auth/providers/keycloak";
import { type KeycloakProfile } from "next-auth/providers/keycloak";
import { type JWT } from "next-auth/jwt";
import { type OAuthConfig } from "next-auth/providers";
import { env } from "~/env.mjs";
import { prisma } from "~/server/db";
@ -66,10 +64,10 @@ export const authOptions: NextAuthOptions = {
*
* @see https://stackoverflow.com/a/75526977
*/
async jwt({ token, account }) {
jwt({ token, account }) {
if (account) {
token.id_token = account.id_token
token.provider = account.provider
token.id_token = account?.id_token
token.provider = account?.provider
}
return token
},
@ -104,10 +102,9 @@ export const authOptions: NextAuthOptions = {
*/
async signOut({ token }: { token: JWT }) {
if (token.provider === "keycloak") {
const issuerUrl = (authOptions.providers.find(p => p.id === "keycloak") as OAuthConfig<KeycloakProfile>).options!.issuer!
const logOutUrl = new URL(`${issuerUrl}/protocol/openid-connect/logout`)
logOutUrl.searchParams.set("id_token_hint", token.id_token!)
await fetch(logOutUrl);
const logOutURL = new URL(`${env.KEYCLOAK_ISSUER}/protocol/openid-connect/logout`)
logOutURL.searchParams.set("id_token_hint", token.id_token ?? '')
await fetch(logOutURL);
}
},
}