Skip to content
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] Add authentication to Toolpad Core #3609

Merged
merged 140 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
461b19d
init: Add auth pages to playground app
bharatkashyap Jun 13, 2024
b4712c4
Merge branch 'master' of github.com:mui/mui-toolpad into toolpad-core…
bharatkashyap Jun 13, 2024
55eb08e
wip: Clean up
bharatkashyap Jun 13, 2024
334288b
fix: Lint
bharatkashyap Jun 13, 2024
d1399c0
fix: Missed
bharatkashyap Jun 13, 2024
87fa644
Merge remote-tracking branch 'upstream/master' into pr/3609
Janpot Jun 18, 2024
d32d986
Batch of changes
Janpot Jun 18, 2024
ae2f352
Merge branch 'master' into toolpad-core-auth
bharatkashyap Jun 19, 2024
781aae9
Merge branch 'toolpad-core-auth' of github.com:bharatkashyap/mui-tool…
bharatkashyap Jun 19, 2024
f62244e
fix: Broken merge
bharatkashyap Jun 19, 2024
0fc1812
fix: Rename `auth-error` to `auth/error`
bharatkashyap Jun 19, 2024
39272e9
fix: Style changes for Credentials form
bharatkashyap Jun 19, 2024
4b81c0f
Merge branch 'master' into toolpad-core-auth
bharatkashyap Jun 21, 2024
0ee065c
fix: CI
bharatkashyap Jun 21, 2024
3aa4c3b
fix: Add prop-types for docs
bharatkashyap Jun 21, 2024
53ae9b7
WIP
Janpot Jun 25, 2024
bab1320
fix auth in pages router
Janpot Jun 25, 2024
4915f32
Merge remote-tracking branch 'upstream/master' into pr/3609
Janpot Jun 25, 2024
3e93ab7
User flow
Janpot Jun 25, 2024
536d535
tweaks
Janpot Jun 25, 2024
b469551
Merge remote-tracking branch 'upstream/master' into pr/3609
Janpot Jun 26, 2024
174442c
Add basic test
Janpot Jun 26, 2024
8459f29
Begin docs
Janpot Jun 26, 2024
a005117
Fix typo
Janpot Jun 26, 2024
1a4731a
lint
Janpot Jun 26, 2024
2c190a2
frfgr
Janpot Jun 26, 2024
56b0256
Remove background
Janpot Jun 26, 2024
8adeef5
Add tests
Janpot Jun 26, 2024
d063c32
Update SignInPage.tsx
Janpot Jun 26, 2024
caaba76
Add public page
Janpot Jun 27, 2024
b5ac9b4
docs: Fix typos, more content to Account
bharatkashyap Jun 28, 2024
5695d06
Merge branch 'master' of github.com:mui/mui-toolpad into toolpad-core…
bharatkashyap Jun 28, 2024
01f2191
Merge branch 'master' of github.com:mui/mui-toolpad into toolpad-core…
bharatkashyap Jul 1, 2024
d72fbec
fix: Proptypes
bharatkashyap Jul 1, 2024
63683e2
fix: CI
bharatkashyap Jul 1, 2024
9f6f67e
fix: ci
bharatkashyap Jul 3, 2024
0054171
fix: CI, finally
bharatkashyap Jul 3, 2024
d1d4316
Merge branch 'master' into toolpad-core-auth
bharatkashyap Jul 3, 2024
3afc720
wip: Improve `credentialsProvider` support
bharatkashyap Jul 4, 2024
66144bb
feat: CredentialsProvider improvements
bharatkashyap Jul 4, 2024
3e9551d
Merge branch 'toolpad-core-auth' of github.com:bharatkashyap/mui-tool…
bharatkashyap Jul 4, 2024
13b1824
Merge branch 'master' into toolpad-core-auth
bharatkashyap Jul 4, 2024
f6f9a8a
fix: Update proptypes
bharatkashyap Jul 4, 2024
5c7ad8b
Merge branch 'toolpad-core-auth' of github.com:bharatkashyap/mui-tool…
bharatkashyap Jul 4, 2024
c23bcf6
fix: `docs:typescript`
bharatkashyap Jul 4, 2024
9a1f1c7
fix: Remove divider if no `OAuth` providers
bharatkashyap Jul 5, 2024
e5f20be
fix: Misc for demos
bharatkashyap Jul 6, 2024
dbaee51
fix: `credentials` provider for Next.js pages playground
bharatkashyap Jul 10, 2024
2e35386
fix: Misc. on auth pages playground
bharatkashyap Jul 10, 2024
0211d27
fix: Remove notifs on successful auth
bharatkashyap Jul 10, 2024
99f9b88
fix: Needless exports
bharatkashyap Jul 10, 2024
0b2b624
fix: Major changes from reviews
bharatkashyap Jul 10, 2024
6aa4749
Merge branch 'master' of github.com:mui/mui-toolpad into toolpad-core…
bharatkashyap Jul 10, 2024
739aca8
fix: Problems with `beta-19`
bharatkashyap Jul 10, 2024
cb15e87
fix: Drop `required: true` for pages app
bharatkashyap Jul 10, 2024
6705a18
fix: Match test with minor UI change
bharatkashyap Jul 10, 2024
4d52271
test: Setup tests for playground Next.js app
bharatkashyap Jul 10, 2024
88ccdd8
feat: Add playwright tests to playground app
bharatkashyap Jul 11, 2024
299ef52
fix: Add playground playwright tests
bharatkashyap Jul 11, 2024
e9ce877
fix: `proptypes`
bharatkashyap Jul 11, 2024
a34546b
fix: unnecessary else
bharatkashyap Jul 11, 2024
eb544a6
fix: lint, ignore unresolved in demos
bharatkashyap Jul 11, 2024
1b938cd
fix: CI
bharatkashyap Jul 11, 2024
6decf84
fix: CI
bharatkashyap Jul 11, 2024
c8d611f
fix: Add `componentProps` for customization, fix for `autofocus`
bharatkashyap Jul 11, 2024
e3b3373
fix: Add to API
bharatkashyap Jul 11, 2024
2976e7a
fix: Runtime error on themed demo
bharatkashyap Jul 11, 2024
d715b2f
fix: Local tests, not for CI
bharatkashyap Jul 11, 2024
9e9cde5
fix: `docs:typescript`
bharatkashyap Jul 11, 2024
cdb20b5
fix: Remove from `CI`
bharatkashyap Jul 11, 2024
a031656
fix: `mode` === "system" causing `palette` mal-formed
bharatkashyap Jul 11, 2024
5dc229f
fix: Don't make page scroll by default
bharatkashyap Jul 11, 2024
93f91d6
fix: This should be a pre-commit hook
bharatkashyap Jul 11, 2024
f3cc43f
fix: Use Icon components
bharatkashyap Jul 11, 2024
5255d07
fix: More fixes to the branding demo
bharatkashyap Jul 11, 2024
1c0c15d
fix: `mode` should never be `null`
bharatkashyap Jul 11, 2024
54f26d3
feat: Add latest version to core docs
bharatkashyap Jul 11, 2024
361e2b2
fix: Add auth examples and update docs
bharatkashyap Jul 11, 2024
e96fb7c
fix: Example apps
bharatkashyap Jul 12, 2024
877cc25
fix: `markdownlint`
bharatkashyap Jul 12, 2024
cf4cde4
Merge branch 'master' of github.com:mui/mui-toolpad into toolpad-core…
bharatkashyap Jul 12, 2024
13f3ebe
fix: Not needed
bharatkashyap Jul 12, 2024
ac73348
fix: Address feedback
bharatkashyap Jul 13, 2024
ea3f4c7
Merge branch 'master' of github.com:mui/mui-toolpad into toolpad-core…
bharatkashyap Jul 13, 2024
758ac45
fix: Don't throw inside docs example
bharatkashyap Jul 13, 2024
add83a9
fix: Update example along with playground
bharatkashyap Jul 13, 2024
331232a
fix: lint
bharatkashyap Jul 13, 2024
c2dc414
Merge branch 'master' of github.com:mui/mui-toolpad into toolpad-core…
bharatkashyap Jul 14, 2024
b4497ea
fix: CI
bharatkashyap Jul 14, 2024
e0221f1
fix: CI again
bharatkashyap Jul 14, 2024
6e30459
fix: Dependencies for examples
bharatkashyap Jul 15, 2024
a6a3e84
fix: Try this?
bharatkashyap Jul 15, 2024
70d08e0
fix: Revert
bharatkashyap Jul 15, 2024
77a36e4
fix: pnpm dedupe
bharatkashyap Jul 15, 2024
76302f4
Merge branch 'master' into toolpad-core-auth
bharatkashyap Jul 15, 2024
9e9803d
fix: Address more feedback, plus some tweaks
bharatkashyap Jul 16, 2024
76b2c16
Merge branch 'toolpad-core-auth' of github.com:bharatkashyap/mui-tool…
bharatkashyap Jul 16, 2024
d9372f3
fix: Docs tweaks
bharatkashyap Jul 16, 2024
3e015bd
fix: Vale
bharatkashyap Jul 16, 2024
03af9de
Merge branch 'master' into toolpad-core-auth
bharatkashyap Jul 16, 2024
8acf683
fix: Lint
bharatkashyap Jul 16, 2024
82156d8
Merge branch 'toolpad-core-auth' of github.com:bharatkashyap/mui-tool…
bharatkashyap Jul 16, 2024
f6837c9
fix: Jan feedback
bharatkashyap Jul 20, 2024
25a61b8
Merge branch 'master' of github.com:mui/mui-toolpad into toolpad-core…
bharatkashyap Jul 20, 2024
208c502
fix: Merge changes
bharatkashyap Jul 20, 2024
799cbe1
fix: Some changes to `<Account />`
bharatkashyap Jul 20, 2024
d21db58
fix: Add `<Account />` API changes
bharatkashyap Jul 20, 2024
cc7aca3
fix: Change `<Account/>` demo on `DashboardLayout` page
bharatkashyap Jul 20, 2024
1aa62e8
fix: Vale
bharatkashyap Jul 20, 2024
fd30c66
Merge branch 'master' of github.com:mui/mui-toolpad into toolpad-core…
bharatkashyap Jul 22, 2024
faabae3
fix: not needed
bharatkashyap Jul 22, 2024
a6bfb00
fix: pnpm dedupe
bharatkashyap Jul 22, 2024
805d508
Merge branch 'master' into toolpad-core-auth
Janpot Jul 22, 2024
6c9e3f3
fix: remove playwright
bharatkashyap Jul 23, 2024
339a2eb
Merge branch 'toolpad-core-auth' of github.com:bharatkashyap/mui-tool…
bharatkashyap Jul 23, 2024
435d768
Merge branch 'master' of github.com:mui/mui-toolpad into toolpad-core…
bharatkashyap Jul 23, 2024
1916886
fix: pnpm dedupe
bharatkashyap Jul 23, 2024
3664521
Update package.json
Janpot Jul 23, 2024
67b7ae9
Update package.json
Janpot Jul 23, 2024
62033aa
fix: Some `vale` warnings
bharatkashyap Jul 23, 2024
7b00b52
Merge branch 'master' into toolpad-core-auth
bharatkashyap Jul 23, 2024
f6e4336
Merge branch 'toolpad-core-auth' of github.com:bharatkashyap/mui-tool…
bharatkashyap Jul 23, 2024
9131ca2
fix: Typo
bharatkashyap Jul 24, 2024
06d605f
fix: Do this in a separate PR
bharatkashyap Jul 24, 2024
30f3ec8
Merge branch 'master' of github.com:mui/mui-toolpad into toolpad-core…
bharatkashyap Jul 25, 2024
c54d22b
fix: Dashboard Account demo content spacing
bharatkashyap Jul 25, 2024
54b628d
fix: This should be a pre-commit hook
bharatkashyap Jul 25, 2024
885b06b
fix: Should also be a pre-commit hook
bharatkashyap Jul 25, 2024
4f8d253
fix: Migrate navigation types
bharatkashyap Jul 29, 2024
4e9ae6e
fix: Make example work
bharatkashyap Jul 30, 2024
5889ea8
fix: Upgrade examples
bharatkashyap Jul 31, 2024
742daa4
fix: `dedupe`
bharatkashyap Jul 31, 2024
877b047
fix: Review
bharatkashyap Jul 31, 2024
e6dc77f
fix: Resolve "TODO"
bharatkashyap Jul 31, 2024
4439766
fix: `Unstable_Grid2` is unresolved
bharatkashyap Jul 31, 2024
7c884f6
fix: Add demos to landing page
bharatkashyap Jul 31, 2024
02fbb37
Merge branch 'master' of github.com:mui/mui-toolpad into toolpad-core…
bharatkashyap Jul 31, 2024
391b33f
fix: Improve instructions
bharatkashyap Jul 31, 2024
f9ca96f
fix: Improve landing page
bharatkashyap Jul 31, 2024
ac6f0ca
Merge branch 'master' of github.com:mui/mui-toolpad into toolpad-core…
bharatkashyap Aug 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ build

.generated
.github
.coverage
2 changes: 2 additions & 0 deletions docs/data/toolpad/core/all-components/all-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
<p class="description">This page contains an index to the components included in Toolpad Core.</p>

- [App Provider](/toolpad/core/react-app-provider/)
- [Account](/toolpad/core/react-account/)
- [Dashboard Layout](/toolpad/core/react-dashboard-layout/)
- [Data Grid](/toolpad/core/react-data-grid/)
- [Sign In Page](/toolpad/core/react-sign-in-page/)
47 changes: 47 additions & 0 deletions docs/data/toolpad/core/components/account/AccountCustom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as React from 'react';
import { Account, AuthenticationContext, SessionContext } from '@toolpad/core';

export default function AccountCustom() {
const [session, setSession] = React.useState(null);
const authentication = React.useMemo(() => {
return {
signIn: () => {
setSession({
user: {
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
});
},
signOut: () => {
setSession(null);
},
};
}, []);

return (
// preview-start
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
<Account
slotProps={{
signInButton: {
color: 'info',
variant: 'outlined',
sx: {
color: 'primaryDark',
fontFamily: 'Inter',
fontSize: '1em',
},
},
signOutButton: { color: 'primary', variant: 'outlined' },
}}
signInLabel="Login"
signOutLabel="Logout"
/>
</SessionContext.Provider>
</AuthenticationContext.Provider>
// preview-end
);
}
52 changes: 52 additions & 0 deletions docs/data/toolpad/core/components/account/AccountCustom.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as React from 'react';
import {
Account,
AuthenticationContext,
SessionContext,
Session,
} from '@toolpad/core';

export default function AccountCustom() {
const [session, setSession] = React.useState<Session | null>(null);
const authentication = React.useMemo(() => {
return {
signIn: () => {
setSession({
user: {
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
});
},
signOut: () => {
setSession(null);
},
};
}, []);

return (
// preview-start
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
<Account
slotProps={{
signInButton: {
color: 'info',
variant: 'outlined',
sx: {
color: 'primaryDark',
fontFamily: 'Inter',
fontSize: '1em',
},
},
signOutButton: { color: 'primary', variant: 'outlined' },
}}
signInLabel="Login"
signOutLabel="Logout"
/>
</SessionContext.Provider>
</AuthenticationContext.Provider>
// preview-end
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
<Account
slotProps={{
signInButton: {
color: 'info',
variant: 'outlined',
sx: {
color: 'primaryDark',
fontFamily: 'Inter',
fontSize: '1em',
},
},
signOutButton: { color: 'primary', variant: 'outlined' },
}}
signInLabel="Login"
signOutLabel="Logout"
/>
</SessionContext.Provider>
</AuthenticationContext.Provider>
30 changes: 30 additions & 0 deletions docs/data/toolpad/core/components/account/AccountDemo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as React from 'react';
import { Account, AuthenticationContext, SessionContext } from '@toolpad/core';

export default function AccountDemo() {
const [session, setSession] = React.useState(null);
const authentication = React.useMemo(() => {
return {
signIn: () => {
setSession({
user: {
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
});
},
signOut: () => {
setSession(null);
},
};
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
<Account />
</SessionContext.Provider>
</AuthenticationContext.Provider>
);
}
35 changes: 35 additions & 0 deletions docs/data/toolpad/core/components/account/AccountDemo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from 'react';
import {
Account,
AuthenticationContext,
SessionContext,
Session,
} from '@toolpad/core';

export default function AccountDemo() {
const [session, setSession] = React.useState<Session | null>(null);
const authentication = React.useMemo(() => {
return {
signIn: () => {
setSession({
user: {
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
});
},
signOut: () => {
setSession(null);
},
};
}, []);

return (
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
<Account />
</SessionContext.Provider>
</AuthenticationContext.Provider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<AuthenticationContext.Provider value={authentication}>
<SessionContext.Provider value={session}>
<Account />
</SessionContext.Provider>
</AuthenticationContext.Provider>
37 changes: 37 additions & 0 deletions docs/data/toolpad/core/components/account/AccountWithDashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { AppProvider, DashboardLayout } from '@toolpad/core';

export default function AccountWithDashboard() {
const [session, setSession] = React.useState({
user: {
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
});
const authentication = React.useMemo(() => {
return {
signIn: () => {
setSession({
user: {
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
});
},
signOut: () => {
setSession(null);
},
};
}, []);

return (
<AppProvider session={session} authentication={authentication}>
<DashboardLayout>
<Box sx={{ px: 6, py: 2 }}>Dashboard content</Box>
</DashboardLayout>
</AppProvider>
);
}
37 changes: 37 additions & 0 deletions docs/data/toolpad/core/components/account/AccountWithDashboard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { Session, AppProvider, DashboardLayout } from '@toolpad/core';

export default function AccountWithDashboard() {
const [session, setSession] = React.useState<Session | null>({
user: {
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
});
const authentication = React.useMemo(() => {
return {
signIn: () => {
setSession({
user: {
name: 'Bharat Kashyap',
email: '[email protected]',
image: 'https://avatars.githubusercontent.com/u/19550456',
},
});
},
signOut: () => {
setSession(null);
},
};
}, []);

return (
<AppProvider session={session} authentication={authentication}>
<DashboardLayout>
<Box sx={{ px: 6, py: 2 }}>Dashboard content</Box>
</DashboardLayout>
</AppProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<DashboardLayout>
<Box sx={{ px: 6, py: 2 }}>Dashboard content</Box>
</DashboardLayout>
29 changes: 29 additions & 0 deletions docs/data/toolpad/core/components/account/account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
productId: toolpad-core
title: Account
components: Account
---

# Account
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a bit more context. Explanation about why and how to use this.


<p class="description">A component that renders an account management dropdown for your application.</p>

The `Account` component is a quick and easy way to display an account management menu for authenticated users. It is deeply integrated with the `SignInPage` and `DashboardLayout` components, meaning that it automatically appears in the top navigation bar inside `DashboardLayout` once your users have signed in through the `SignInPage`.

## States

When signed out, the component renders as an inline sign in button within the dashboard layout. If a `session` object is present, the component is rendered as a dropdown containing the user's account details as well as an option to sign out.

{{"demo": "AccountDemo.js", "bg": "gradient" }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow up
The demo has some layout shift when signing in


## Customization

### Components

`Account` can take different labels for the sign in and sign out buttons through the `signInLabel` and `signOutLabel` props. Deeper changes can be made by passing in `slotProps` to the underlying components.

{{"demo": "AccountCustom.js", "bg": "gradient" }}

### 🚧 Composition

The `Account` component allows adding your own menu options, including deeply nested options. This is in progress.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
productId: toolpad-core
title: Dashboard Layout
components: AppProvider, DashboardLayout
components: AppProvider, DashboardLayout, Account
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a section and demo on the user button. And an explanation on how to customize it (slots?).

---

# Dashboard Layout
Expand Down Expand Up @@ -50,3 +50,13 @@ The main navigation items that can be used are:
Navigation links have an optional `action` prop that can be used to render any content on the right-side of the respective list item, such as badges with numbers, or buttons to toggle a popover menu.

{{"demo": "DashboardLayoutNavigationActions.js", "height": 500, "iframe": true}}

## Account
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind the name UserAccount if we used it by the way, seems clearer to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with components starting with use is that the docs builder scripts recognise them as hooks. To me <Account /> seems okay. We can take up modifying the script in case it seems unusable

Copy link
Member

@apedroferreira apedroferreira Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, if that's the main/only reason I guess we can make the part that checks "use" in the scripts be case-sensitive? Anyway it's not that important to change this name, only if everyone agrees.


The `DashboardLayout` comes integrated with the [`<Account />`](/toolpad/core/react-account/) component. It renders as an account management menu when a user is signed in – a `session` object is present – and a button when not.

:::warning
The use of an `iframe` may cause some spacing issues in the following demo.
:::

{{"demo": "../account/AccountWithDashboard.js", "iframe": true, "height": 320 }}
5 changes: 0 additions & 5 deletions docs/data/toolpad/core/components/index.md

This file was deleted.

46 changes: 46 additions & 0 deletions docs/data/toolpad/core/components/sign-in-page/AuthJsSignInApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint-disable import/no-unresolved */

import * as React from 'react';
import { AuthError } from 'next-auth';

import { SignInPage } from '@toolpad/core/SignInPage';
import { providerMap, signIn } from './auth';

export default function AuthJsSignInApp() {
return (
<SignInPage
providers={providerMap}
signIn={async (provider, formData, callbackUrl) => {
'use server';
try {
return await signIn(provider.id, {
...(formData && {
email: formData.get('email'),
password: formData.get('password'),
}),
redirectTo: callbackUrl ?? '/',
});
} catch (error) {
if (error instanceof Error && error.message === 'NEXT_REDIRECT') {
throw error;
}
// Handle Auth.js errors
if (error instanceof AuthError) {
return {
error:
error.type === 'CredentialsSignin'
? 'Invalid credentials.'
: 'An error with Auth.js occurred.',
type: error.type,
};
}
// An error boundary must exist to handle unknown errors
return {
error: 'Something went wrong.',
type: 'UnknownError',
};
}
}}
/>
);
}
Loading
Loading