Stop custom token decoding - use Base44's built-in authentication
Your current code:
Why it fails:
Base44 magic link auth creates its own session cookies that your custom decoder can't read. You're trying to decode Base44's session cookie format with your custom logic.
Replace ALL your custom auth logic with:
const base44 = createClientFromRequest(req);
const user = await base44.auth.me();
if (!user) {
return jsonResponse({ error: "Not authenticated" }, 401);
}
// user.id, user.email, user.role are now available ✅Created new endpoint: /functions/mobileAPI_v2
✅ This version uses Base44's built-in auth - no custom token decoding!
Removed: parseSessionCookie()
No longer manually parse cookies - Base44 SDK handles this
Removed: parseAuthorizationHeader()
No longer extract tokens manually
Removed: decodeSessionToken()
No longer decode base64 tokens - Base44 does this internally
Removed: getAuthenticatedUser()
No longer manually look up users in RorkUser
Added: base44.auth.me()
Single line to get authenticated user - works with Base44 sessions
Added: Fallback to RorkUser
If RorkUser exists, merge additional data like phone number
Update Rork API endpoint
Change from /functions/mobileAPI to /functions/mobileAPI_v2
const API_URL = 'https://your-app.base44.com/functions/mobileAPI_v2';
Keep credentials: 'include'
This is still required - don't change your fetch calls
fetch(API_URL, {
method: 'POST',
credentials: 'include', // ✅ Keep this
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'me' })
})Test authentication
After updating, test that 'me' action returns your user data
Simpler Code
~150 lines removed, single auth call
More Reliable
Uses Base44's battle-tested auth
Automatic Updates
Base44 handles session expiry, refresh
Better Security
No custom token parsing vulnerabilities