Skip to content

Commit cd2a7db

Browse files
udpated PAR example
1 parent 49dfc47 commit cd2a7db

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

EXAMPLES.md

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -757,36 +757,28 @@ const sessionCookieValue = await generateSessionCookie(
757757
## Programmatic Pushed Authentication Requests (PAR)
758758

759759
The method `startInteractiveLogin` can be called with authorizationParams to initiate an interactive login flow.
760-
It's similar to the `handleLogin` method but `authorizationParams` are explicitly provided here.
761760
The code collects authorization parameters on the server side rather than constructing them directly in the browser.
762761

763762
```typescript
764763
// app/api/auth/login/route.ts
765-
import { getAuth0 } from '@auth0/nextjs-auth0';
766-
import { NextRequest } from 'next/server';
767-
import { auth0Config } from '@/auth0-config';
764+
import { auth0 } from "./lib/auth0";
765+
import { NextRequest } from "next/server";
768766

769767
export const GET = async (req: NextRequest) => {
770-
const auth0 = getAuth0(auth0Config);
771-
772-
try {
773-
// Extract custom parameters from request URL if needed
774-
const searchParams = Object.fromEntries(req.nextUrl.searchParams.entries());
775-
776-
// Call startInteractiveLogin with optional parameters
777-
return auth0.startInteractiveLogin({
778-
returnTo: searchParams.returnTo || '/dashboard',
779-
authorizationParameters: {
780-
// Add any custom auth parameters
781-
prompt: searchParams.prompt,
782-
login_hint: searchParams.login_hint,
783-
// You can specify a different audience for specific resources
784-
audience: searchParams.audience || auth0Config.authorizationParams.audience
785-
}
786-
});
787-
} catch (error) {
788-
console.error('Login error:', error);
789-
return new Response('Login failed', { status: 500 });
790-
}
768+
// Extract custom parameters from request URL if needed
769+
const searchParams = Object.fromEntries(req.nextUrl.searchParams.entries());
770+
771+
// Call startInteractiveLogin with optional parameters
772+
return auth0.startInteractiveLogin({
773+
// a custom returnTo URL can be specified
774+
returnTo: "/dashboard",
775+
authorizationParameters: {
776+
prompt: searchParams.prompt,
777+
login_hint: searchParams.login_hint,
778+
// Add any custom auth parameters if required
779+
audience: "custom-audience"
780+
}
781+
});
791782
};
783+
792784
```

0 commit comments

Comments
 (0)