Repository navigation
feat(auth): make auth.hasToken() public - #307
Merged
Merged
Conversation
hasToken() already existed on the internal auth surface for the analytics module. Apps need the same check to skip auth.me() for anonymous visitors (a request that can only 401) without reading localStorage themselves, so move it onto the public AuthModule and drop InternalAuthModule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017E6ba4b3bzDDW4VXPzWFbw
Contributor
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/sdk@0.8.52-pr.307.064de09Prefer not to change any import paths? Install using npm alias so your code still imports npm i "@base44/sdk@npm:@base44-preview/sdk@0.8.52-pr.307.064de09"Or add it to your {
"dependencies": {
"@base44/sdk": "npm:@base44-preview/sdk@0.8.52-pr.307.064de09"
}
}
Preview published to npm registry — try new features instantly! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
base44.auth.hasToken()already exists. The analytics module uses it to skipauth.me()for anonymous visitors, but it was typed on the internal-onlyInternalAuthModule. This PR moves it onto the publicAuthModule, documents it, and removesInternalAuthModule. Runtime behavior is unchanged.Why: apps need the same check. The TanStack Start app template calls
auth.me()on every page load. For an anonymous visitor that request can only return 401, and in production those 401s showed up on most new TanStack apps (base44-dev/apper#28607). That template currently works around this withgetAccessToken(), which readslocalStoragedirectly. That breaks when a token is set withsetToken(token, false), and it duplicates state the client already tracks.Semantics (documented in the JSDoc):
isAuthenticated()to check validity.createClient({ token }),setToken()andlogout().false.Testing
tsc --noEmit,npm run test:typesandvitest run tests/unit(318 passed) all pass. The existinghasTokentest now calls the publicclient.authwithout a cast.typedocreports the same 11 warnings as before, all pre-existing. The newhasToken()section renders inAuthModule.mdx, and its links tome(),isAuthenticated(),createClient(),setToken()andlogout()resolve.🤖 Generated with Claude Code
https://claude.ai/code/session_017E6ba4b3bzDDW4VXPzWFbw
Generated by Claude Code