Skip to content

fix(auth): normalize AUTH_TYPE to uppercase to prevent silent redirect loop - #6810

Merged
shahargl merged 1 commit into
keephq:mainfrom
alex-percy:fix/auth-type-case-sensitivity
Sep 11, 2026
Merged

shahargl merged 1 commit into
keephq:mainfrom
alex-percy:fix/auth-type-case-sensitivity

Conversation

@alex-percy

Copy link
Copy Markdown
Contributor

Summary

One-line fix: adds .toUpperCase() when reading the AUTH_TYPE environment variable in the frontend, so that lowercase values like db correctly match the uppercase AuthType enum ("DB").

Problem

Setting AUTH_TYPE=db (lowercase) works on the backend (Python, case-insensitive) but silently breaks the frontend. The AuthType enum and backward-compat constants are all uppercase:

// utils/authenticationType.ts
export enum AuthType {
  DB = "DB",
  NOAUTH = "NOAUTH",
  // ...
}
export const MULTI_TENANT = "MULTI_TENANT";
export const SINGLE_TENANT = "SINGLE_TENANT";
export const NO_AUTH = "NO_AUTH";

But auth.config.ts compared the raw env value without normalizing:

const authTypeEnv = runtimeEnv("AUTH_TYPE"); // "db"
// ... none of the comparisons match "db" ...
: (authTypeEnv as AuthType); // "db" cast — not "DB"

This causes baseProviderConfigs["db"] to return undefined, silently falling back to the NoAuth credentials provider. The signin page then auto-calls signIn("credentials"), creating a NextAuth session without a valid Keep JWT, which produces an infinite redirect loop with no error message.

Fix

-const authTypeEnv = runtimeEnv("AUTH_TYPE");
+const authTypeEnv = runtimeEnv("AUTH_TYPE")?.toUpperCase();

All enum values and backward-compat constants are already uppercase, so this is safe.

Fixes #6809

…t loop

The AuthType enum values and backward-compat constants (MULTI_TENANT,
SINGLE_TENANT, NO_AUTH) are all uppercase, but the raw AUTH_TYPE env
var was compared without case normalization. Setting AUTH_TYPE=db
(lowercase) — which the backend Python code accepts fine — caused the
frontend to fall through to a raw TypeScript cast that produced an
invalid enum value. The provider config lookup then returned undefined,
silently defaulting to the NoAuth credentials provider, which
auto-signs in without a login form and creates an infinite redirect
loop.

Adding .toUpperCase() to the env read makes 'db', 'DB', and 'Db' all
resolve to AuthType.DB correctly.

Fixes #6809
@CLAassistant

CLAassistant commented Sep 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@shahargl shahargl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@shahargl
shahargl merged commit e255d6a into keephq:main Sep 11, 2026
9 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

💪 Fantastic work @alex-percy! Your very first PR to keep has been merged! 🎉🥳

You've just taken your first step into open-source, and we couldn't be happier to have you onboard. 🙌
If you're feeling adventurous, why not dive into another issue and keep contributing? The community would love to see more from you! 🚀

For any support, feel free to reach out on the community: https://slack.keephq.dev. Happy coding! 👩‍💻👨‍💻

@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 30.43%. Comparing base (620adaf) to head (62522b1).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6810      +/-   ##
==========================================
- Coverage   30.45%   30.43%   -0.02%     
==========================================
  Files         101      101              
  Lines       11785    11791       +6     
==========================================
  Hits         3589     3589              
- Misses       8196     8202       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: AUTH_TYPE is case-sensitive in frontend but case-insensitive in backend — lowercase 'db' causes silent redirect loop

4 participants