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
docs: fix state parameter type documentation to match implementation (#327)
The state parameter in getSignInUrl/getSignUpUrl is implemented as a
string (matching OAuth 2.0 RFC 6749 specification), but the documentation
showed examples using object literals without JSON serialization.
This commit updates all documentation examples to:
- Show explicit JSON.stringify() when passing state objects
- Show explicit JSON.parse() when reading state in callbacks
- Update the type table to reflect string | undefined instead of Record<string, any>
- Add a note explaining that state is an opaque string per OAuth 2.0 spec
Fixes#326
|`refreshToken`|`string`| Refresh token for session renewal |
137
+
|`impersonator`|`Impersonator \| undefined`| Present if user is being impersonated |
138
+
|`oauthTokens`|`OauthTokens \| undefined`| OAuth tokens from upstream provider |
139
+
|`authenticationMethod`|`string \| undefined`| How the user authenticated (e.g., 'password', 'google-oauth'). Only available during initial login |
140
+
|`organizationId`|`string \| undefined`| Organization context of authentication |
141
+
|`state`|`string\| undefined`| Custom state string passed through the authentication flow (parse with JSON.parse if needed)|
141
142
142
143
**Note**: `authenticationMethod` is only provided during the initial authentication callback. It will not be available in subsequent requests or session refreshes.
143
144
@@ -229,10 +230,10 @@ export default async function HomePage() {
229
230
230
231
// You can also pass custom state data through the auth flow
231
232
constsignInUrlWithState=awaitgetSignInUrl({
232
-
state: {
233
+
state:JSON.stringify({
233
234
teamId:'team_123',
234
235
referrer:'homepage',
235
-
},
236
+
}),
236
237
});
237
238
238
239
return (
@@ -408,41 +409,46 @@ JWT tokens are sensitive credentials and should be handled carefully:
408
409
409
410
### Passing Custom State Through Authentication
410
411
411
-
You can pass custom state data through the authentication flow using the `state` parameter. This data will be available in the `onSuccess` callback after authentication:
412
+
You can pass custom state data through the authentication flow using the `state` parameter. The state parameter is a string value that gets passed through OAuth and returned in the callback. To pass complex data, serialize it as JSON:
412
413
413
414
```ts
414
-
// When generating sign-in/sign-up URLs
415
+
// When generating sign-in/sign-up URLs, serialize your data as JSON
415
416
const signInUrl = await getSignInUrl({
416
-
state: {
417
+
state: JSON.stringify({
417
418
teamId: 'team_123',
418
419
feature: 'billing',
419
420
referrer: 'pricing-page',
420
421
timestamp: Date.now(),
421
-
},
422
+
}),
422
423
});
423
424
424
425
// The state data is available in the callback handler
425
426
export const GET = handleAuth({
426
427
onSuccess: async ({ user, state }) => {
428
+
// Parse the state string back to an object
429
+
const customData = state ? JSON.parse(state) : null;
> **Note**: The `state` parameter is an opaque string as defined by OAuth 2.0 (RFC 6749). If you need to pass structured data, you must serialize it yourself using `JSON.stringify()` and parse it with `JSON.parse()` in the callback.
0 commit comments