mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-28 15:56:39 +00:00
fix bug causing auto provision to override manually created users
This commit is contained in:
@@ -352,20 +352,38 @@ export async function validateOidcCallback(
|
|||||||
|
|
||||||
if (!userOrgInfo.length) {
|
if (!userOrgInfo.length) {
|
||||||
if (existingUser) {
|
if (existingUser) {
|
||||||
// delete the user
|
// get existing user orgs
|
||||||
// cascade will also delete org users
|
const existingUserOrgs = await db
|
||||||
|
.select()
|
||||||
|
.from(userOrgs)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(userOrgs.userId, existingUser.userId),
|
||||||
|
eq(userOrgs.autoProvisioned, false)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
await db
|
if (!existingUserOrgs.length) {
|
||||||
.delete(users)
|
// delete the user
|
||||||
.where(eq(users.userId, existingUser.userId));
|
await db
|
||||||
|
.delete(users)
|
||||||
|
.where(eq(users.userId, existingUser.userId));
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.UNAUTHORIZED,
|
||||||
|
`No policies matched for ${userIdentifier}. This user must be added to an organization before logging in.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// no orgs to provision and user doesn't exist
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.UNAUTHORIZED,
|
||||||
|
`No policies matched for ${userIdentifier}. This user must be added to an organization before logging in.`
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return next(
|
|
||||||
createHttpError(
|
|
||||||
HttpCode.UNAUTHORIZED,
|
|
||||||
`No policies matched for ${userIdentifier}. This user must be added to an organization before logging in.`
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const orgUserCounts: { orgId: string; userCount: number }[] = [];
|
const orgUserCounts: { orgId: string; userCount: number }[] = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user