fix(nextauth): check if originLinkAccount is not undefined
This commit is contained in:
parent
7cdcf52149
commit
453e48c2b5
1 changed files with 16 additions and 9 deletions
|
|
@ -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,10 +56,15 @@ 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;
|
||||
return originLinkAccount(data);
|
||||
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);
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Reference in a new issue