Skip to content

Commit

Permalink
Fix auth state not updating after login
Browse files Browse the repository at this point in the history
  • Loading branch information
dac09 committed Jan 23, 2024
1 parent 2f10d9a commit 8b082f6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/auth-providers/dbAuth/web/src/dbAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ export function createDbAuthClient({
// @TODO getToken and getUserMetadata are not required with SSR-cookie auth
// Remove these functions
getToken,
getUserMetadata: getToken,
// This forces useReauthenticate to call getCurrentUser. If we make the change in useReauthenticate
// it would break all other auth providers. getUserMetadata is a "shortcut" for getting the user
// without fetching the actual currentUser from the server. With cookie auth, _all_ providers will need
// to fetch it from the server
getUserMetadata: () => true as any,
// -----
forgotPassword,
resetPassword,
Expand Down
2 changes: 2 additions & 0 deletions packages/auth/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ declare global {
RWJS_API_URL: string

__REDWOOD__APP_TITLE: string

RWJS_EXP_STREAMING_SSR: boolean
}

var __REDWOOD__SERVER__AUTH_STATE__: AuthProviderState<any>
Expand Down
4 changes: 1 addition & 3 deletions packages/auth/src/AuthProvider/useReauthenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ export const useReauthenticate = <TUser>(
client: authImplementation.client,
})
} else {
await getToken()

const currentUser = skipFetchCurrentUser ? null : await getCurrentUser()

setAuthProviderState((oldState) => ({
...oldState,
userMetadata,
currentUser,
isAuthenticated: true,
isAuthenticated: !!currentUser,
loading: false,
client: authImplementation.client,
}))
Expand Down

0 comments on commit 8b082f6

Please sign in to comment.