You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use handleRedirectCallback() instead of relying solely on a reactive
useSession: await the redirect exchange so the page redirects only when done,
show the error instead of hanging on 'Signing you in…', and use the returned
returnTo (set via signInWithOauthConnection({ returnTo })) to send the user back
where they were — no sessionStorage bookkeeping.
After login the user is redirected to the callback URL you registered on your Client. `@faable/auth-js` reads the tokens from the URL automatically; the route just needs to mount the SDK and send the user somewhere afterwards.
117
+
After login the user is redirected to the callback URL you registered on your Client. `@faable/auth-js` reads the tokens from the URL automatically, but your callback route should **await** that processing so it can:
118
+
119
+
- redirect **only once** the token exchange has finished, and
120
+
- show an error instead of getting stuck on "Signing you in…" if the exchange fails (e.g. an expired login attempt).
121
+
122
+
Call `handleRedirectCallback()` for exactly that. It returns `{ error, returnTo }`: on success send the user onward (to `returnTo` if you set one when starting the login — see below), and on failure surface `error.message`.
118
123
119
124
<Tabsitems={['App Router', 'Pages Router']}>
120
125
<Tabs.Tab>
@@ -123,18 +128,22 @@ After login the user is redirected to the callback URL you registered on your Cl
> **Returning the user to where they were.** Pass `returnTo` when you start the
180
+
> login and it round-trips back to you here — no `sessionStorage` bookkeeping
181
+
> needed. It is stored locally next to the PKCE verifier and never sent to the
182
+
> server:
183
+
>
184
+
> ```ts
185
+
>awaitfaableauth.signInWithOauthConnection({
186
+
> redirectTo: window.location.origin+"/callback",
187
+
> returnTo: "/dashboard",
188
+
> });
189
+
>```
190
+
166
191
## Accessing user state
167
192
168
193
Anywhere inside the provider, use the `useSession` and `useUser` hooks to read the current session and user profile. Call `signInWithOauthConnection` on the client to start the login, and `signOut` to clear it.
0 commit comments