Skip to content

Commit

Permalink
fix: fixed issue where auth state would update incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
Pagebakers committed Dec 23, 2023
1 parent 47fa013 commit e7ec7f8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-mangos-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@saas-ui/auth': patch
---

Fixed issue where auth state would not update correctly
11 changes: 6 additions & 5 deletions packages/saas-ui-auth/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ export const AuthProvider = <TUser extends User = DefaultUser>({
const checkAuth = useCallback(async () => {
try {
if (onGetToken) {
setAuthenticated(!!(await onGetToken()))
const isAuthenticated = !!(await onGetToken())
setAuthenticated(isAuthenticated)
return isAuthenticated
}
} catch (e) {
setAuthenticated(false)
Expand All @@ -179,15 +181,14 @@ export const AuthProvider = <TUser extends User = DefaultUser>({

useEffect(() => {
window.addEventListener('focus', checkAuth)

checkAuth()

return () => {
window.removeEventListener('focus', checkAuth)
}
}, [checkAuth])

const loadUser = useCallback(async () => {
const isAuthenticated = await checkAuth()

if (isAuthenticated) {
const user = await onLoadUser()

Expand All @@ -199,7 +200,7 @@ export const AuthProvider = <TUser extends User = DefaultUser>({
}

setLoading(false)
}, [onLoadUser, isAuthenticated])
}, [onLoadUser, checkAuth])

const signUp = useCallback(
async (params: AuthParams, options?: AuthOptions) => {
Expand Down
13 changes: 13 additions & 0 deletions packages/saas-ui-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,25 @@
},
"./anatomy/src": {
"default": "./src/anatomy/index.ts"
},
"./components": {
"types": "./dist/components/index.d.ts",
"import": "./dist/components/index.mjs",
"require": "./dist/components/index.js"
},
"./components/*": {
"types": "./dist/components/*.d.ts",
"import": "./dist/components/*.mjs",
"require": "./dist/components/*.js"
}
},
"typesVersions": {
"*": {
"anatomy": [
"./dist/anatomy/index.d.ts"
],
"components": [
"./dist/components/index.d.ts"
]
}
},
Expand Down

0 comments on commit e7ec7f8

Please sign in to comment.