Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

fix OIDC login

Blue Mouse22788be22fb8
diff --git a/backend/apps/community/src/auth/auth.controller.ts b/backend/apps/community/src/auth/auth.controller.ts
index d12e3aac5..367291e4e 100644
--- a/backend/apps/community/src/auth/auth.controller.ts
+++ b/backend/apps/community/src/auth/auth.controller.ts
@@ -410,7 +410,18 @@ export class AuthController {
try {
await this.authService.processOidcToken(code, hash, redirectUrl)
+ return res.status(HttpStatus.CREATED).end()
} catch (reason) {
+ // If the session already contains user data (duplicate callback), treat as success
+ try {
+ const isReady = await this.authService.isOidcSessionReady(hash)
+ if (isReady) {
+ return res.status(HttpStatus.CREATED).end()
+ }
+ } catch {
+ // ignore readiness check errors
+ }
+
console.error('[ERROR] OIDC Callback Error:', reason)
return res
.status(HttpStatus.BAD_REQUEST)
diff --git a/backend/apps/community/src/auth/auth.service.ts b/backend/apps/community/src/auth/auth.service.ts
index 1426721c5..f61fb6fc7 100644
--- a/backend/apps/community/src/auth/auth.service.ts
+++ b/backend/apps/community/src/auth/auth.service.ts
@@ -451,6 +451,24 @@ export class AuthService {
await redis.set(oidcRedisKey, dataToStore, 'EX', REDIS_OIDC_SESSION_TIMEOUT)
}
+ /**
+ * Checks whether the OIDC session identified by the provided state already contains
+ * resolved user data. This is used to gracefully handle duplicate callback deliveries
+ * or double-invocation scenarios in the client where the same code might be posted twice.
+ */
+ async isOidcSessionReady(state: string): Promise<boolean> {
+ const oidcRedisKey = getOIDCRedisKey(state)
+ const data = await redis.get(oidcRedisKey)
+
+ return Boolean(data && data.length > 0)
+ }
+
+ async doesOidcSessionExist(state: string): Promise<boolean> {
+ const oidcRedisKey = getOIDCRedisKey(state)
+ const exists = await redis.exists(oidcRedisKey)
+ return Boolean(exists)
+ }
+
async processHash(state: string) {
if (!state) {
throw new BadRequestException('Missing state parameter')
diff --git a/web/app/pages/Auth/Socialised/index.tsx b/web/app/pages/Auth/Socialised/index.tsx
index ecd2819d8..0c16720b0 100644
--- a/web/app/pages/Auth/Socialised/index.tsx
+++ b/web/app/pages/Auth/Socialised/index.tsx
@@ -25,6 +25,13 @@ const Socialised = () => {
const code = searchParams.get('code')
const provider = _split(state, ':')[0]
+ // Prevent duplicate callback processing in React 18 StrictMode (dev) or other double-invocation scenarios
+ const processedKey = state ? `oidc_processed:${state}` : null
+ if (processedKey && sessionStorage.getItem(processedKey) === '1') {
+ setLoading(false)
+ return
+ }
+
const processCode = async () => {
if (!state || !provider) {
setIsError(true)
@@ -63,6 +70,9 @@ const Socialised = () => {
}
try {
+ if (processedKey) {
+ sessionStorage.setItem(processedKey, '1')
+ }
await processSSOTokenCommunityEdition(code, state, `${window.location.origin}${routes.socialised}`)
} catch (reason) {
setIsError(true)