-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:clerk/clerk-docs
- Loading branch information
Showing
399 changed files
with
8,430 additions
and
4,069 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
```tsx | ||
import { createClerkClient } from '@clerk/backend' | ||
|
||
export async function GET(req: Request) { | ||
const clerkClient = createClerkClient({ | ||
secretKey: process.env.CLERK_SECRET_KEY, | ||
publishableKey: process.env.CLERK_PUBLISHABLE_KEY, | ||
}) | ||
|
||
const { isSignedIn } = await clerkClient.authenticateRequest(req, { | ||
jwtKey: process.env.CLERK_JWT_KEY, | ||
authorizedParties: ['https://example.com'], | ||
}) | ||
|
||
if (!isSignedIn) { | ||
return Response.json({ status: 401 }) | ||
} | ||
|
||
// Add logic to perform protected actions | ||
|
||
return Response.json({ message: 'This is a reply' }) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The [`<ClerkProvider>`](/docs/components/clerk-provider) component provides session and user context to Clerk's hooks and components. It's recommended to wrap your entire app at the entry point with `<ClerkProvider>` to make authentication globally accessible. See the [reference docs](/docs/components/clerk-provider) for other configuration options. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
The following example demonstrates how to create a custom OAuth sign-in flow for [Google accounts](/docs/authentication/social-connections/google). | ||
|
||
```tsx {{ filename: 'app/(auth)/sign-in.tsx', collapsible: true }} | ||
import React from 'react' | ||
import * as WebBrowser from 'expo-web-browser' | ||
import { Text, View, Button } from 'react-native' | ||
import { Link } from 'expo-router' | ||
import { useOAuth } from '@clerk/clerk-expo' | ||
import * as Linking from 'expo-linking' | ||
|
||
export const useWarmUpBrowser = () => { | ||
React.useEffect(() => { | ||
// Warm up the android browser to improve UX | ||
// https://docs.expo.dev/guides/authentication/#improving-user-experience | ||
void WebBrowser.warmUpAsync() | ||
return () => { | ||
void WebBrowser.coolDownAsync() | ||
} | ||
}, []) | ||
} | ||
|
||
WebBrowser.maybeCompleteAuthSession() | ||
|
||
export default function Page() { | ||
useWarmUpBrowser() | ||
|
||
const { startOAuthFlow } = useOAuth({ strategy: 'oauth_google' }) | ||
|
||
const onPress = React.useCallback(async () => { | ||
try { | ||
const { createdSessionId, signIn, signUp, setActive } = await startOAuthFlow({ | ||
redirectUrl: Linking.createURL('/dashboard', { scheme: 'myapp' }), | ||
}) | ||
|
||
// If sign in was successful, set the active session | ||
if (createdSessionId) { | ||
setActive!({ session: createdSessionId }) | ||
} else { | ||
// Use signIn or signUp returned from startOAuthFlow | ||
// for next steps, such as MFA | ||
} | ||
} catch (err) { | ||
// See https://clerk.com/docs/custom-flows/error-handling | ||
// for more info on error handling | ||
console.error(JSON.stringify(err, null, 2)) | ||
} | ||
}, []) | ||
|
||
return ( | ||
<View> | ||
<Link href="/"> | ||
<Text>Home</Text> | ||
</Link> | ||
<Button title="Sign in with Google" onPress={onPress} /> | ||
</View> | ||
) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
- [`useUser()`](/docs/references/react/use-user){{ target: '_blank' }} | ||
- [`useClerk()`](/docs/references/react/use-clerk){{ target: '_blank' }} | ||
- [`useAuth()`](/docs/references/react/use-auth){{ target: '_blank' }} | ||
- [`useSignIn()`](/docs/references/react/use-sign-in){{ target: '_blank' }} | ||
- [`useSignUp()`](/docs/references/react/use-sign-up){{ target: '_blank' }} | ||
- [`useSession()`](/docs/references/react/use-session){{ target: '_blank' }} | ||
- [`useSessionList()`](/docs/references/react/use-session-list){{ target: '_blank' }} | ||
- [`useOrganization()`](/docs/references/react/use-organization){{ target: '_blank' }} | ||
- [`useOrganizationList()`](/docs/references/react/use-organization-list){{ target: '_blank' }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The following example uses the [`has()`](/docs/references/nextjs/auth-object#has) helper to check if the user has verified their credentials within a specific time period. The `strict` configuration sets the time period to 10 minutes. If the user hasn't verified their credentials within 10 minutes, the `reverificationErrorResponse` utility is used to return an error. | ||
|
||
```tsx {{ filename: 'app/api/reverification-example/route.ts' }} | ||
import { auth, reverificationErrorResponse } from '@clerk/nextjs/server' | ||
|
||
export const POST = async (req: Request) => { | ||
const { has } = await auth() | ||
|
||
// Check if the user has *not* verified their credentials within the past 10 minutes. | ||
const shouldUserRevalidate = !has({ reverification: 'strict' }) | ||
|
||
// If the user hasn't reverified, return an error with the matching configuration (e.g., `strict`) | ||
if (shouldUserRevalidate) { | ||
return reverificationErrorResponse('strict') | ||
} | ||
|
||
// If the user has verified credentials, return a successful response | ||
return new Response({ success: true }) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
> [!CAUTION] | ||
> The entire session token has a max size of 4kb. Exceeding this size can have adverse effects, including a possible infinite redirect loop for users who exceed this size in Next.js applications. | ||
> It's recommended to move particularly large claims out of the JWT and fetch these using a separate API call from your backend. | ||
> [Learn more](/docs/backend-requests/resources/session-tokens#size-limitations). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.