1
0
Fork 0

fix(nextauth): check if originLinkAccount is not undefined

This commit is contained in:
Vojtěch Mareš 2023-09-07 11:43:05 +02:00
parent 7cdcf52149
commit 453e48c2b5
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D

View file

@ -37,7 +37,7 @@ declare module "next-auth" {
*
* @see https://stackoverflow.com/a/75526977
*/
declare module 'next-auth/jwt' {
declare module "next-auth/jwt" {
interface JWT {
id_token?: string;
provider?: string;
@ -56,9 +56,14 @@ const originLinkAccount = adapter.linkAccount;
*/
adapter.linkAccount = (account: AdapterAccount) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { 'not-before-policy': _, refresh_expires_in, ...data } = account;
const { "not-before-policy": _, refresh_expires_in, ...data } = account;
if (!originLinkAccount) {
return;
}
return originLinkAccount(data);
}
};
/**
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
@ -83,10 +88,10 @@ export const authOptions: NextAuthOptions = {
*/
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
return token;
},
},
adapter: adapter,
@ -119,12 +124,14 @@ export const authOptions: NextAuthOptions = {
*/
async signOut({ token }: { token: JWT }) {
if (token.provider === "keycloak") {
const logOutURL = new URL(`${env.KEYCLOAK_ISSUER}/protocol/openid-connect/logout`)
logOutURL.searchParams.set("id_token_hint", token.id_token ?? '')
const logOutURL = new URL(
`${env.KEYCLOAK_ISSUER}/protocol/openid-connect/logout`
);
logOutURL.searchParams.set("id_token_hint", token.id_token ?? "");
await fetch(logOutURL);
}
},
}
},
};
/**