spine-framework 0.3.89 → 0.3.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -116,10 +116,11 @@ export function AppsRegistryProvider({ children }: AppsRegistryProviderProps) {
116
116
  }
117
117
  }
118
118
 
119
- // Fetch once when user changes (login/logout), not on every render
119
+ // Fetch when user identity or roles change (roles may update after registration)
120
+ const rolesKey = user?.roles?.join(',') || ''
120
121
  useEffect(() => {
121
122
  fetchApps()
122
- }, [user?.id, user?.account_id])
123
+ }, [user?.id, user?.account_id, rolesKey])
123
124
 
124
125
  const routableApps = apps.filter(
125
126
  app => app.route_prefix != null && app.renderer !== 'none'
@@ -163,8 +163,10 @@ export function AuthProvider({ children }: AuthProviderProps) {
163
163
  }
164
164
  }
165
165
 
166
- const [user, setUser] = useState<User | null>(getStoredUser)
167
- const [isLoading, setIsLoading] = useState(false) // Start with false, will set to true only if we need to check
166
+ const storedUser = getStoredUser()
167
+ const [user, setUser] = useState<User | null>(storedUser)
168
+ // If we have a stored user, start loading to verify context before rendering routes
169
+ const [isLoading, setIsLoading] = useState(!!storedUser)
168
170
  const [isLoggingIn, setIsLoggingIn] = useState(false)
169
171
 
170
172
  // Save user to sessionStorage whenever it changes
@@ -269,13 +271,26 @@ export function AuthProvider({ children }: AuthProviderProps) {
269
271
  // Check initial auth state
270
272
  const checkAuth = async () => {
271
273
  try {
272
- // Early exit if user is already loaded
274
+ // If user is loaded from sessionStorage, verify context from server
275
+ // before rendering routes (isLoading starts true in this case)
273
276
  if (user) {
274
- console.log('User already loaded, skipping auth check:', user.id)
277
+ console.log('User loaded from storage, verifying context:', user.id)
278
+ const { data: { session } } = await supabase.auth.getSession()
279
+ if (session?.user) {
280
+ const userContext = await fetchUserContext()
281
+ if (userContext) {
282
+ setUserWithStorage(userContext)
283
+ setAccountId(userContext.account_id)
284
+ }
285
+ } else {
286
+ // Session expired — clear stored user
287
+ setUserWithStorage(null)
288
+ setAccountId(null)
289
+ }
275
290
  return
276
291
  }
277
292
 
278
- // Only show loading if we actually need to check auth
293
+ // No stored user show loading spinner while checking
279
294
  setIsLoading(true)
280
295
  console.log('Checking initial auth state...')
281
296
  const { data: { session } } = await supabase.auth.getSession()
@@ -34,6 +34,7 @@
34
34
  import React, { useState, useEffect, useCallback } from 'react'
35
35
  import { Link, useNavigate, useSearchParams } from 'react-router-dom'
36
36
  import { LoadingSpinner } from '../../components/ui/LoadingSpinner'
37
+ import { useAuth } from '../../contexts/AuthContext'
37
38
  import { supabase } from '../../lib/supabase'
38
39
 
39
40
  // ─── TYPES ────────────────────────────────────────────────────────────────────
@@ -132,6 +133,7 @@ function getPostRegistrationRedirect(
132
133
  export function RegisterPage() {
133
134
  const [searchParams] = useSearchParams()
134
135
  const navigate = useNavigate()
136
+ const { refreshUser } = useAuth()
135
137
  const inviteToken = searchParams.get('t')
136
138
 
137
139
  // Registration config
@@ -342,6 +344,10 @@ export function RegisterPage() {
342
344
  return
343
345
  }
344
346
 
347
+ // Re-fetch user context so roles are populated (complete-registration
348
+ // sets role_id, but the initial auth fetch may have raced ahead of it)
349
+ await refreshUser()
350
+
345
351
  // Navigate to configured post-registration destination
346
352
  const redirectPath = getPostRegistrationRedirect(regConfig, searchParams, false)
347
353
  navigate(redirectPath, { replace: true })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spine-framework",
3
- "version": "0.3.89",
3
+ "version": "0.3.91",
4
4
  "description": "Multi-tenant, modular application platform for modern SaaS systems",
5
5
  "type": "module",
6
6
  "bin": {