Skip to content

fix(auth): clear the stored token when me() rejects it - #264

Merged
davidsu merged 5 commits into
mainfrom
fix/clear-token-before-login-redirect
Oct 21, 2026
Merged

davidsu merged 5 commits into
mainfrom
fix/clear-token-before-login-redirect

Conversation

@davidsu

@davidsu davidsu commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

A rejected token left in localStorage boots the next page with it. Apps that serve their own login page then get another 401 and redirect to /login forever: the loop that hit ~3k custom-auth apps when the legacy app-user signing key was cut off (https://base44workspace.slack.com/archives/C095K108GKU/p1787509962872049).

me() now clears the stored token when it answers 401 and storage still holds the token the request sent. Any other failure (5xx, 429, network) keeps it, and so does a token stored while the request was in flight (a login in this or another tab). redirectToLogin() no longer touches storage, so a valid session survives a "Sign in" click or an abandoned login.

This is the same rule as the script base44-dev/apper#21743 injects into served apps; once apps pick this SDK up on their next build/publish, that script can be retired.

@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/sdk@0.8.54-pr.264.cfcaa05

Prefer not to change any import paths? Install using npm alias so your code still imports @base44/sdk:

npm i "@base44/sdk@npm:@base44-preview/sdk@0.8.54-pr.264.cfcaa05"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "@base44/sdk": "npm:@base44-preview/sdk@0.8.54-pr.264.cfcaa05"
  }
}

Preview published to npm registry — try new features instantly!

@github-actions github-actions Bot added the docs-draft PR has auto-drafted documentation suggestions label Aug 27, 2026
Comment thread packages/sdk/src/modules/auth.ts Outdated
@guyofeck
guyofeck self-requested a review October 20, 2026 10:14
redirectToLogin() cleared storage on every call, so a valid session was lost
on a transient me() failure (requiresAuth treats any error as signed out), a
"Sign in" click while signed in, or an abandoned login. Clear instead when
me() gets a 401 and storage still holds the token it sent, the same rule as
the server-side script this replaces. A token stored mid-flight is kept.

Task: https://b44sync.base44.app/rd-hub/tasks/BASE-12635
Task file: https://github.com/base44-dev/suss-tasks/blob/7bad58778ebc784b3e49b15fb4faee1016a9384f/apper/retire_clear_token_script/land_sdk_264.md

agent: sdk.264
@davidsu davidsu changed the title fix(auth): drop the stored token before redirecting to login fix(auth): clear the stored token when me() rejects it Oct 20, 2026

@guyofeck guyofeck left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM


Generated by Claude Code

@davidsu
davidsu merged commit 7b2ca1e into main Oct 21, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-draft PR has auto-drafted documentation suggestions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants