implement supabase auth into router context
i want to implement the supabase auth into my router context, but when i try to call the context auth in beforeLoad layout, it's not updated as in my AuthProvider component. when i change the code in AuthProvider, it will infinite loop. I've try this repo to implement in my code, but it's still not show the context auth in beforeLoad layout. can you guys know what's the problem??
5 Replies
continuing-cyan•7mo ago
can you provide a complete minimal example?
extended-salmonOP•7mo ago
wait
extended-salmonOP•7mo ago
the infinite loop issue that i have is more or less like this discussion
https://github.com/TanStack/router/discussions/1238
GitHub
Getting out of memory error when navigating to authenticated route ...
I have a Vite React app which is using Supabase and Google OAuth for authentication. I have an AuthContext to keep track of authentication state. It has the following type: export interface AuthCon...
extended-salmonOP•7mo ago
anyone able to help? 🥲
I think putting auth in the beforeLoad context will not work. because the
beforeLoad()
context will be executed once at the first time of access. while in the auth provider, the state will update every time the user has logged in or not. so I think I will use the traditional way by calling the useAuth hooks on the layout component instead of conditioning in the beforeLoad()
context. maybe in the next update I hope, beforeLoad()
can update the context every time there is a change in the state (for example in AuthProvider)harsh-harlequin•7mo ago
Last year, I worked with a user to get a working example repo with Supabase Auth working with Router
https://github.com/dave-hawkins/tanstack-router-supabase-auth
You'll want to take a look at
-
main.tsx
- routes/
_auth.tsx
-
routes/public/auth-callback.tsx`GitHub
GitHub - dave-hawkins/tanstack-router-supabase-auth: Tanstack route...
Tanstack router + supabase auth starter repo. Contribute to dave-hawkins/tanstack-router-supabase-auth development by creating an account on GitHub.