hotfix: fallback oauth find (#250)
This commit is contained in:
parent
bbeea5b0ec
commit
55eba480ac
1 changed files with 5 additions and 3 deletions
|
@ -58,7 +58,7 @@ export const withOAuth =
|
||||||
|
|
||||||
let existingOauth;
|
let existingOauth;
|
||||||
try {
|
try {
|
||||||
existingOauth = await prisma.oAuth.findUnique({
|
existingOauth = await prisma.oAuth.findUniqueOrThrow({
|
||||||
where: {
|
where: {
|
||||||
provider_oauthId: {
|
provider_oauthId: {
|
||||||
provider: provider.toUpperCase() as OauthProviders,
|
provider: provider.toUpperCase() as OauthProviders,
|
||||||
|
@ -67,7 +67,8 @@ export const withOAuth =
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.code === 'P2002') {
|
logger.debug(`Failed to find existing oauth. Using fallback. ${e}`);
|
||||||
|
if (e.code === 'P2022' || e.code === 'P2025') {
|
||||||
const existing = await prisma.user.findFirst({
|
const existing = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
oauth: {
|
oauth: {
|
||||||
|
@ -82,6 +83,7 @@ export const withOAuth =
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
existingOauth = existing?.oauth?.find((o) => o.provider === provider.toUpperCase());
|
existingOauth = existing?.oauth?.find((o) => o.provider === provider.toUpperCase());
|
||||||
|
existingOauth.lastCase = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +155,7 @@ export const withOAuth =
|
||||||
logger.info(`User ${user.username} (${user.id}) logged in via oauth(${provider})`);
|
logger.info(`User ${user.username} (${user.id}) logged in via oauth(${provider})`);
|
||||||
|
|
||||||
return res.redirect('/dashboard');
|
return res.redirect('/dashboard');
|
||||||
} else if (existingOauth) {
|
} else if ((existingOauth && existingOauth.lastCase) || existingOauth) {
|
||||||
await prisma.oAuth.update({
|
await prisma.oAuth.update({
|
||||||
where: {
|
where: {
|
||||||
id: existingOauth!.id,
|
id: existingOauth!.id,
|
||||||
|
|
Loading…
Reference in a new issue