-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Add
passkey
provider support and example (#4063)
- Loading branch information
1 parent
45d2188
commit 0610dcf
Showing
32 changed files
with
830 additions
and
115 deletions.
There are no files selected for viewing
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
45 changes: 0 additions & 45 deletions
45
docs/data/toolpad/core/components/sign-in-page/AuthJsSignInApp.js
This file was deleted.
Oops, something went wrong.
49 changes: 0 additions & 49 deletions
49
docs/data/toolpad/core/components/sign-in-page/AuthJsSignInApp.tsx
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
docs/data/toolpad/core/components/sign-in-page/PasskeySignInPage.js
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,28 @@ | ||
import * as React from 'react'; | ||
import { AppProvider } from '@toolpad/core/AppProvider'; | ||
import { SignInPage } from '@toolpad/core/SignInPage'; | ||
import { useTheme } from '@mui/material/styles'; | ||
// preview-start | ||
const providers = [{ id: 'passkey', name: 'Passkey' }]; | ||
// preview-end | ||
|
||
const signIn = async (provider) => { | ||
const promise = new Promise((resolve) => { | ||
setTimeout(() => { | ||
alert(`Signing in with ${provider.id}`); | ||
resolve(); | ||
}, 500); | ||
}); | ||
return promise; | ||
}; | ||
|
||
export default function PasskeySignInPage() { | ||
const theme = useTheme(); | ||
return ( | ||
// preview-start | ||
<AppProvider theme={theme}> | ||
<SignInPage signIn={signIn} providers={providers} /> | ||
</AppProvider> | ||
// preview-end | ||
); | ||
} |
28 changes: 28 additions & 0 deletions
28
docs/data/toolpad/core/components/sign-in-page/PasskeySignInPage.tsx
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,28 @@ | ||
import * as React from 'react'; | ||
import { AppProvider } from '@toolpad/core/AppProvider'; | ||
import { SignInPage, AuthProvider } from '@toolpad/core/SignInPage'; | ||
import { useTheme } from '@mui/material/styles'; | ||
// preview-start | ||
const providers = [{ id: 'passkey', name: 'Passkey' }]; | ||
// preview-end | ||
|
||
const signIn: (provider: AuthProvider) => void = async (provider) => { | ||
const promise = new Promise<void>((resolve) => { | ||
setTimeout(() => { | ||
alert(`Signing in with ${provider.id}`); | ||
resolve(); | ||
}, 500); | ||
}); | ||
return promise; | ||
}; | ||
|
||
export default function PasskeySignInPage() { | ||
const theme = useTheme(); | ||
return ( | ||
// preview-start | ||
<AppProvider theme={theme}> | ||
<SignInPage signIn={signIn} providers={providers} /> | ||
</AppProvider> | ||
// preview-end | ||
); | ||
} |
7 changes: 7 additions & 0 deletions
7
docs/data/toolpad/core/components/sign-in-page/PasskeySignInPage.tsx.preview
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,7 @@ | ||
const providers = [{ id: 'passkey', name: 'Passkey' }]; | ||
|
||
// ... | ||
|
||
<AppProvider theme={theme}> | ||
<SignInPage signIn={signIn} providers={providers} /> | ||
</AppProvider> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
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,5 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
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,50 @@ | ||
# Toolpad Core Playground - Next.js App Router with Passkey | ||
|
||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). | ||
|
||
## Getting Started | ||
|
||
1. You need to have a Postgres database running. You can use the following docker command to start a Postgres database: | ||
|
||
```bash | ||
docker run --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres | ||
``` | ||
|
||
2. For the database created above, the connection string is `postgresql://postgres:postgres@localhost:5432/postgres`. | ||
|
||
3. Update the `DATABASE_URL` environment variable in the `.env` file with the connection string for the database you created above. | ||
|
||
4. Then, generate the Prisma Client: | ||
|
||
```bash | ||
npx prisma generate --schema=./src/prisma/schema.prisma | ||
``` | ||
|
||
5. Finally, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
# or | ||
pnpm dev | ||
# or | ||
bun dev | ||
``` | ||
|
||
6. Open [http://localhost:3000](http://localhost:3000) with your browser to see the app running. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
||
Check out the [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. |
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,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
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 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {}; | ||
|
||
export default nextConfig; |
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,32 @@ | ||
{ | ||
"name": "core-auth-nextjs-passkey", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"dev": "next dev", | ||
"lint": "next lint" | ||
}, | ||
"dependencies": { | ||
"@auth/prisma-adapter": "2.4.2", | ||
"@emotion/react": "11.13.3", | ||
"@emotion/styled": "11.13.0", | ||
"@mui/icons-material": "6.0.2", | ||
"@mui/lab": "6.0.0-beta.9", | ||
"@mui/material": "6.0.2", | ||
"@mui/material-nextjs": "6.0.2", | ||
"@prisma/client": "5.19.1", | ||
"@simplewebauthn/browser": "9.0.1", | ||
"@simplewebauthn/server": "9.0.3", | ||
"@toolpad/core": "workspace:*", | ||
"next": "14.2.7", | ||
"next-auth": "5.0.0-beta.20", | ||
"react": "18.3.1", | ||
"react-dom": "18.3.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "22.5.1", | ||
"@types/react": "18.3.5", | ||
"@types/react-dom": "18.3.0", | ||
"eslint-config-next": "14.2.7", | ||
"prisma": "5.19.1" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/core-auth-nextjs-passkey/src/app/(dashboard)/layout.tsx
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,11 @@ | ||
import * as React from 'react'; | ||
import { DashboardLayout } from '@toolpad/core/DashboardLayout'; | ||
import { PageContainer } from '@toolpad/core/PageContainer'; | ||
|
||
export default async function DashboardPagesLayout(props: { children: React.ReactNode }) { | ||
return ( | ||
<DashboardLayout> | ||
<PageContainer>{props.children}</PageContainer> | ||
</DashboardLayout> | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
examples/core-auth-nextjs-passkey/src/app/(dashboard)/orders/page.tsx
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,33 @@ | ||
import * as React from 'react'; | ||
import Typography from '@mui/material/Typography'; | ||
import Box from '@mui/material/Box'; | ||
import { redirect } from 'next/navigation'; | ||
import { headers } from 'next/headers'; | ||
import { auth } from '../../../auth'; | ||
|
||
export default async function OrdersPage() { | ||
const session = await auth(); | ||
const currentUrl = headers().get('referer') || 'http://localhost:3000'; | ||
|
||
if (!session) { | ||
// Get the current URL to redirect to signIn with `callbackUrl` | ||
const redirectUrl = new URL('/auth/signin', currentUrl); | ||
redirectUrl.searchParams.set('callbackUrl', currentUrl); | ||
|
||
redirect(redirectUrl.toString()); | ||
} | ||
return ( | ||
<Box | ||
sx={{ | ||
my: 4, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
textAlign: 'center', | ||
}} | ||
> | ||
<Typography sx={{ mb: 2 }}>Welcome to the Toolpad orders!</Typography> | ||
</Box> | ||
); | ||
} |
Oops, something went wrong.