Skip to content

Commit

Permalink
Handle initialSession changes in context provider (#591)
Browse files Browse the repository at this point in the history
* Handle initialSession changes in context provider

Resolves #586

* Add changeset

---------

Co-authored-by: Andrew Smith <a.smith@silentworks.co.uk>
  • Loading branch information
joshuabaker and silentworks authored Jul 16, 2023
1 parent 1619e93 commit 1dc9c9c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-seas-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@supabase/auth-helpers-react': patch
---

fix: Handle initialSession changes in context provider
6 changes: 6 additions & 0 deletions packages/react/src/components/SessionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export const SessionContextProvider = ({
const [isLoading, setIsLoading] = useState<boolean>(!initialSession);
const [error, setError] = useState<AuthError>();

useEffect(() => {
if (!session && initialSession) {
setSession(initialSession)
}
}, [session, initialSession]);

useEffect(() => {
let mounted = true;

Expand Down

0 comments on commit 1dc9c9c

Please sign in to comment.