-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathpage.tsx
35 lines (30 loc) · 1.17 KB
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { WorkOS } from '@workos-inc/node';
// This example uses Next.js with React Server Components.
// Because this page is an RSC, the code stays on the server, which allows
// us to use the WorkOS Node SDK without exposing our API key to the client.
//
// If your application is a single page app (SPA), you will need to:
// - create a form that can POST to an endpoint in your backend
// - call the `getAuthorizationURL` method in that endpoint
// - redirect the user to the returned URL
const workos = new WorkOS(process.env.WORKOS_API_KEY);
export default function Basic({
searchParams,
}: {
searchParams: { [key: string]: string | string[] | undefined };
}) {
const authKitUrl = workos.userManagement.getAuthorizationUrl({
clientId: process.env.WORKOS_CLIENT_ID || '',
provider: 'authkit',
redirectUri: 'http://localhost:3000/using-hosted-authkit/basic/callback',
});
const result = JSON.parse(String(searchParams.response ?? '{ "error": null }'));
return (
<main>
<h1>Using hosted AuthKit</h1>
<h2>Basic example</h2>
<a href={authKitUrl}>Sign-in with AuthKit</a>
<pre>{JSON.stringify(result, null, 2)}</pre>
</main>
);
}