-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathpage.tsx
35 lines (30 loc) · 1.19 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 SignInWithGoogleOAuth({
searchParams,
}: {
searchParams: { [key: string]: string | string[] | undefined };
}) {
const googleOAuthUrl = workos.userManagement.getAuthorizationUrl({
clientId: process.env.WORKOS_CLIENT_ID || '',
provider: 'GoogleOAuth',
redirectUri: 'http://localhost:3000/using-your-own-ui/sign-in/google-oauth/callback',
});
const result = JSON.parse(String(searchParams.response ?? '{ "error": null }'));
return (
<main>
<h1>Sign-in</h1>
<h2>Google OAuth</h2>
<a href={googleOAuthUrl}>Continue with Google</a>
<pre>{JSON.stringify(result, null, 2)}</pre>
</main>
);
}