-
-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Support magic links in SignInPage
#4085
Open
bharatkashyap
wants to merge
41
commits into
mui:master
Choose a base branch
from
bharatkashyap:feat/magic-link
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
31ea476
feat: Add `nodemailer` provider to `SignInPage`
bharatkashyap c952172
Merge branch 'master' into feat/magic-link
bharatkashyap 131b443
fix: eslint
bharatkashyap 65e0949
Merge branch 'feat/magic-link' of github.com:bharatkashyap/mui-toolpa…
bharatkashyap c9e3956
Merge branch 'master' into feat/magic-link
bharatkashyap 2c61b88
Merge branch 'master' of github.com:mui/mui-toolpad into feat/magic-link
bharatkashyap bbdddef
Merge branch 'master' into feat/magic-link
bharatkashyap 4d7a335
Merge branch 'master' into feat/magic-link
bharatkashyap c0796ab
Merge branch 'master' into feat/magic-link
bharatkashyap 000f694
Merge branch 'master' into feat/magic-link
bharatkashyap 7882158
Merge branch 'master' into feat/magic-link
bharatkashyap 3b6309d
Merge branch 'master' into feat/magic-link
bharatkashyap 2dd6554
Merge branch 'master' of github.com:mui/mui-toolpad into feat/magic-link
bharatkashyap 31ba678
Merge branch 'master' of github.com:mui/mui-toolpad into feat/magic-link
bharatkashyap 70ef2aa
fix: Add example link to docs
bharatkashyap d390f71
fix: CI
bharatkashyap 4532fb2
Merge branch 'master' of github.com:mui/mui-toolpad into feat/magic-link
bharatkashyap 110a06e
Merge branch 'master' of github.com:mui/mui-toolpad into feat/magic-link
bharatkashyap 55b316f
fix: Simplify magic links docs and fix example
bharatkashyap cf82dc8
fix: lint
bharatkashyap b139284
fix: Add test
bharatkashyap 2ee806b
wip: Test this build
bharatkashyap 02073b5
Merge branch 'master' into feat/magic-link
bharatkashyap f80bfab
fix: CI
bharatkashyap b4ff718
Merge branch 'feat/magic-link' of github.com:bharatkashyap/mui-toolpa…
bharatkashyap dc5ebf4
fix: CI, test build
bharatkashyap c0bf20b
fix: CI
bharatkashyap 2422a15
fix: Test docker deployment and add it to example
bharatkashyap 56ceca0
Merge branch 'master' of github.com:mui/mui-toolpad into feat/magic-link
bharatkashyap 7f68521
fix: CI
bharatkashyap 56b4466
fix: Minor tweaks
bharatkashyap 91d95f0
fix: Jan review
bharatkashyap f139401
fix: CI
bharatkashyap 16f2a3b
Update docs/data/toolpad/core/components/sign-in-page/sign-in-page.md
bharatkashyap 5a1b0b4
Update docs/data/toolpad/core/components/sign-in-page/sign-in-page.md
bharatkashyap 040fcaf
fix: Jan review
bharatkashyap dc9f688
fix: CI
bharatkashyap d534daa
Merge branch 'master' of github.com:mui/mui-toolpad into feat/magic-link
bharatkashyap 22de185
Merge branch 'master' of github.com:mui/mui-toolpad into feat/magic-link
bharatkashyap ffde5f0
fix: lint
bharatkashyap c72c511
Merge branch 'master' of github.com:mui/mui-toolpad into feat/magic-link
bharatkashyap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
docs/data/toolpad/core/components/sign-in-page/MagicLinkAlertSignInPage.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,31 @@ | ||
import * as React from 'react'; | ||
import { SignInPage } from '@toolpad/core/SignInPage'; | ||
import { AppProvider } from '@toolpad/core/AppProvider'; | ||
import { useTheme } from '@mui/material/styles'; | ||
|
||
const providers = [{ id: 'nodemailer', name: 'Email' }]; | ||
|
||
const signIn = async (provider) => { | ||
const promise = new Promise((resolve) => { | ||
setTimeout(() => { | ||
console.log(`Sign in with ${provider.id}`); | ||
// preview-start | ||
resolve({ | ||
success: 'Check your email for a verification link.', | ||
}); | ||
// preview-end | ||
}, 500); | ||
}); | ||
return promise; | ||
}; | ||
|
||
export default function MagicLinkAlertSignInPage() { | ||
const theme = useTheme(); | ||
return ( | ||
// preview-start | ||
<AppProvider theme={theme}> | ||
<SignInPage signIn={signIn} providers={providers} /> | ||
</AppProvider> | ||
// preview-end | ||
); | ||
} |
40 changes: 40 additions & 0 deletions
40
docs/data/toolpad/core/components/sign-in-page/MagicLinkAlertSignInPage.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,40 @@ | ||
import * as React from 'react'; | ||
import { | ||
AuthProvider, | ||
SignInPage, | ||
SupportedAuthProvider, | ||
AuthResponse, | ||
} from '@toolpad/core/SignInPage'; | ||
import { AppProvider } from '@toolpad/core/AppProvider'; | ||
import { useTheme } from '@mui/material/styles'; | ||
|
||
const providers: { id: SupportedAuthProvider; name: string }[] = [ | ||
{ id: 'nodemailer', name: 'Email' }, | ||
]; | ||
|
||
const signIn: (provider: AuthProvider) => Promise<AuthResponse> = async ( | ||
provider, | ||
) => { | ||
const promise = new Promise<AuthResponse>((resolve) => { | ||
setTimeout(() => { | ||
console.log(`Sign in with ${provider.id}`); | ||
// preview-start | ||
resolve({ | ||
success: 'Check your email for a verification link.', | ||
}); | ||
// preview-end | ||
}, 500); | ||
}); | ||
return promise; | ||
}; | ||
|
||
export default function MagicLinkAlertSignInPage() { | ||
const theme = useTheme(); | ||
return ( | ||
// preview-start | ||
<AppProvider theme={theme}> | ||
<SignInPage signIn={signIn} providers={providers} /> | ||
</AppProvider> | ||
// preview-end | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
docs/data/toolpad/core/components/sign-in-page/MagicLinkAlertSignInPage.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,9 @@ | ||
resolve({ | ||
success: 'Check your email for a verification link.', | ||
}); | ||
|
||
// ... | ||
|
||
<AppProvider theme={theme}> | ||
<SignInPage signIn={signIn} providers={providers} /> | ||
</AppProvider> |
30 changes: 30 additions & 0 deletions
30
docs/data/toolpad/core/components/sign-in-page/MagicLinkSignInPage.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,30 @@ | ||
import * as React from 'react'; | ||
import { SignInPage } from '@toolpad/core/SignInPage'; | ||
import { AppProvider } from '@toolpad/core/AppProvider'; | ||
import { useTheme } from '@mui/material/styles'; | ||
|
||
// preview-start | ||
const providers = [{ id: 'nodemailer', name: 'Email' }]; | ||
|
||
// preview-end | ||
|
||
const signIn = async (provider) => { | ||
const promise = new Promise((resolve) => { | ||
setTimeout(() => { | ||
console.log(`Sign in with ${provider.id}`); | ||
resolve(); | ||
}, 500); | ||
}); | ||
return promise; | ||
}; | ||
|
||
export default function MagicLinkSignInPage() { | ||
const theme = useTheme(); | ||
return ( | ||
// preview-start | ||
<AppProvider theme={theme}> | ||
<SignInPage signIn={signIn} providers={providers} /> | ||
</AppProvider> | ||
// preview-end | ||
); | ||
} |
35 changes: 35 additions & 0 deletions
35
docs/data/toolpad/core/components/sign-in-page/MagicLinkSignInPage.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,35 @@ | ||
import * as React from 'react'; | ||
import { | ||
AuthProvider, | ||
SignInPage, | ||
SupportedAuthProvider, | ||
} from '@toolpad/core/SignInPage'; | ||
import { AppProvider } from '@toolpad/core/AppProvider'; | ||
import { useTheme } from '@mui/material/styles'; | ||
|
||
// preview-start | ||
const providers: { id: SupportedAuthProvider; name: string }[] = [ | ||
{ id: 'nodemailer', name: 'Email' }, | ||
]; | ||
// preview-end | ||
|
||
const signIn: (provider: AuthProvider) => void = async (provider) => { | ||
const promise = new Promise<void>((resolve) => { | ||
setTimeout(() => { | ||
console.log(`Sign in with ${provider.id}`); | ||
resolve(); | ||
}, 500); | ||
}); | ||
return promise; | ||
}; | ||
|
||
export default function MagicLinkSignInPage() { | ||
const theme = useTheme(); | ||
return ( | ||
// preview-start | ||
<AppProvider theme={theme}> | ||
<SignInPage signIn={signIn} providers={providers} /> | ||
</AppProvider> | ||
// preview-end | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
docs/data/toolpad/core/components/sign-in-page/MagicLinkSignInPage.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,9 @@ | ||
const providers: { id: SupportedAuthProvider; name: string }[] = [ | ||
{ id: 'nodemailer', name: 'Email' }, | ||
]; | ||
|
||
// ... | ||
|
||
<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
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
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,45 @@ | ||
# Use Node.js 20 Alpine as the base image | ||
FROM node:20-alpine AS builder | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Copy package.json and package-lock.json | ||
COPY package*.json ./ | ||
|
||
# Install dependencies | ||
RUN npm install | ||
|
||
# Copy all files | ||
COPY . . | ||
|
||
# Build the Next.js app | ||
RUN npm run build | ||
|
||
# Start a new stage for a smaller final image | ||
FROM node:20-alpine AS runner | ||
|
||
WORKDIR /app | ||
|
||
# Copy built assets from the builder stage | ||
COPY --from=builder /app/.next ./.next | ||
COPY --from=builder /app/node_modules ./node_modules | ||
COPY --from=builder /app/package.json ./package.json | ||
COPY --from=builder /app/src/prisma ./prisma | ||
|
||
# Set environment variables | ||
ENV NODE_ENV production | ||
ENV PORT 3000 | ||
|
||
# Copy the entrypoint script | ||
COPY entrypoint.sh /entrypoint.sh | ||
RUN chmod +x /entrypoint.sh | ||
|
||
# Set the entrypoint | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
||
# Expose the port Next.js runs on | ||
EXPOSE 3000 | ||
|
||
# Run the Next.js app | ||
CMD ["npm", "start"] |
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,34 @@ | ||
# Toolpad Core Next.js App Router app with email provider | ||
|
||
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 | ||
|
||
First, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
# or | ||
pnpm dev | ||
# or | ||
bun dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
## 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 our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. | ||
Check warning on line 34 in examples/core-auth-nextjs-email/README.md GitHub Actions / runner / vale
|
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,52 @@ | ||
version: '3.8' | ||
|
||
services: | ||
app: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- '3000:3000' | ||
environment: | ||
- DATABASE_URL=${DATABASE_URL} | ||
- AUTH_URL=${AUTH_URL} | ||
- AUTH_TRUST_HOST=true | ||
- NODE_ENV=production | ||
- GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID} | ||
- GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET} | ||
- AUTH_SECRET=${AUTH_SECRET} | ||
- EMAIL_SERVER_HOST=${EMAIL_SERVER_HOST} | ||
- EMAIL_SERVER_PORT=${EMAIL_SERVER_PORT} | ||
- EMAIL_SERVER_USER=${EMAIL_SERVER_USER} | ||
- EMAIL_SERVER_PASSWORD=${EMAIL_SERVER_PASSWORD} | ||
- EMAIL_FROM=${EMAIL_FROM} | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
networks: | ||
- app-network | ||
|
||
db: | ||
image: postgres:13 | ||
environment: | ||
- POSTGRES_USER=${POSTGRES_USER} | ||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD} | ||
- POSTGRES_DB=${POSTGRES_DB} | ||
ports: | ||
- '${POSTGRES_PORT}:5432' | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data | ||
healthcheck: | ||
test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}'] | ||
interval: 5s | ||
timeout: 5s | ||
retries: 5 | ||
networks: | ||
- app-network | ||
|
||
volumes: | ||
postgres_data: | ||
|
||
networks: | ||
app-network: | ||
driver: bridge |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a default success alert that would already show in this demo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a separate demo on the Alerts just below this one, so I think this one is okay? If you think strongly that we should merge them, I can do that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a huge deal, it's just that the first demo doesn't provide any feedback when you press the submit button so maybe that will feel a bit weird if it's the first thing a user tries.
But I just noticed that other demos in the same page work the same... maybe they could always show a standard browser alert or something (instead of a console log that most people will miss), but I guess that's something you can add at any time, doesn't need to block this PR.