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

[docs] Add SignInPage Vite + React Router example #4335

Merged
merged 9 commits into from
Nov 5, 2024

Conversation

bharatkashyap
Copy link
Member

@bharatkashyap bharatkashyap commented Oct 29, 2024

Closes #4326

@bharatkashyap bharatkashyap added the docs Improvements or additions to the documentation label Oct 29, 2024
Copy link
Member

@apedroferreira apedroferreira left a comment

Choose a reason for hiding this comment

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

Looks good, added comments mostly on the integration guide.
Also should we adjust the Vite playground to match this new example more, with a similar structure to the Next.js playgrounds? But that could be done separately too.


### 4. (Optional) Set up authentication

You can use the `SignInPage` component to add authentication along with an external authentication provider of your choice. The following code demonstrates the code required to set up authentication with a mock provider.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
You can use the `SignInPage` component to add authentication along with an external authentication provider of your choice. The following code demonstrates the code required to set up authentication with a mock provider.
You can use the `SignInPage` component to add authentication along with an external authentication provider of your choice. The following code demonstrates how to set up authentication with a mock provider.


You can use the `SignInPage` component to add authentication along with an external authentication provider of your choice. The following code demonstrates the code required to set up authentication with a mock provider.

#### a. Define a `SessionContext` to hold the authentication session
Copy link
Member

Choose a reason for hiding this comment

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

We're supposed to already provide a hook for this, right? And why are we not just passing a session to the AppProvider like you did in the example?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to modify this example to use useSession and an actual authentication service in a follow up. I've updated the wording in this PR to reflect that the SessionContext is being defined to serve as a mock authentication provider. Also, missed writing the step around passing the session to the AppProvider, great catch.

}
```

#### b. Protect routes inside the dashboard layout
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can add this step at the end only, as it makes more sense to create the sign in page first.

Copy link
Member

Choose a reason for hiding this comment

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

Also technically we should be able to protect any pages, not just the pages with the dashboard layout, I guess...
But because useSession probably needs the AppProvider to wrap it this would probably add another level to the React Router configuration, which starts to get kind of cumbersome...
So I think this should be fine for now. Eventually we might even have a better, automatic way to configure protected pages/routes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree, I've reflected that the user is free to protect any other page or layout using a similar process

```

:::info
For a full working example, see the [Toolpad Core Vite app with React Router and authentication example](https://github.com/mui/toolpad/tree/master/examples/core-vite-auth)
Copy link
Member

@apedroferreira apedroferreira Oct 30, 2024

Choose a reason for hiding this comment

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

Are the 2 different examples a bit redundant now? Maybe we should have just one, to match what we do with Next.js

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, we could potentially remove the original example as a follow up to this

{
title: 'Vite with React Router and authentication',
description:
'This app shows you to how to get started using Toolpad Core with Vite, React Router and any external authentication provider',
Copy link
Member

@apedroferreira apedroferreira Oct 30, 2024

Choose a reason for hiding this comment

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

Depending on what feedback we get from users eventually we can replace this example with actual external auth providers like Auth0 and Firebase. But as a generic first step this is probably fine for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, for the follow up to modify this example to use Auth0/Firebase/Supabase and the useSession hook

@apedroferreira
Copy link
Member

Oh, also you might want to call the new example auth-vite or something like that, to match the Next.js example names more.

@bharatkashyap bharatkashyap merged commit 90eaa01 into mui:master Nov 5, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A sign-in page section for vite, react router
2 participants