Next.js
Using the Next.js SDK with the pre-built React UI
If you would like to use the pre-built Scute UI
with your Next.js app, you can do so using the @scute/ui-react
package alongside @scute/nextjs
and @scute/react
. This package would expose the pre-built Auth
and Profile
components which you can use to easily integrate Scute to your current app.
Head over to the example project repo to clone and run this example project and check out the type docs for more scuteClient
methods.
Install the SDK
Install our React SDKs with your favorite package manager:
npm install @scute/nextjs @scute/react @scute/ui-react
Add your credentials to your environment variable handler:
Add the Scute Next.js Handlers (App Router)
In your project under src/app
, create the path auth/[...scute]
. Inside the newly created folder [...scute]
, create a file named route.js
. This file will be the handler for the requests coming in from the pre-built React UI.
The directory structure should look like this:
To implement the handlers, add the code block below to the route.js
file.
Add the UI and the AuthContextProvider
Using the @scute/ui-react
and @scute/react
packages, create an AuthProvider
and the Auth
component. Please refer to the Scute React UI docs for more information.
Add the AuthProvider
to the RootLayout
Wrap the HTML body with the Auth provider inside your root layout file
Once the AuthProvider
is in place, go ahead and add the Auth component to your homepage:
Create a profile page with the Profile
component
Finally, build the profile page to handle the redirect from the home page on successful authentication,
Congratulations! You now have a working Scute instance inside your Next.js app!
Add the Scute Next.js Handlers (Pages Router)
To add the Scute handlers for Pages Router, create the path src/pages/auth
and create a file named [...scute].js
with the below content.
To use Edge runtime, use the following code:
Last updated on