@nauth0/server v0.3.3-canary.0
nauth0
Easy and awesome authentication for NextJS applications using Auth0.
This project is a WIP and is likely to include breaking changes
Installation
Install the dependencies:
yarn add nauth0
Add /lib/nauth0.ts
to your NextJS application. This creates your instantiated nauth0 instance that we'll use in the rest of your application.
import nauth0 from 'nauth0';
export default nauth0({
issuer: process.env.AUTH_ISSUER,
clientId: process.env.AUTH_CLIENT_ID,
clientSecret: process.env.AUTH_CLIENT_SECRET,
redirectUri: 'http://localhost:3000/api/auth/callback',
logoutRedirectUri: 'http://localhost:3000/',
postLoginRedirectUri: 'http://localhost:3000/profile', // Optional global configuration of post login page.
scope: 'openid profile',
session: {
cookieSecret: 'supersecret',
},
});
Add /pages/api/auth/[auth].ts
with the following contents:
import nauth0 from 'lib/nauth0';
export default nauth0.handler();
The Auth0 Domain, Client ID and Client Secret can be found by creating the application within the Auth0 dashboard.
Requirements
- Node >= 12.19.0
Auth0 Configuration
Create a new Regular Web Application with the following settings:
- Allowed Callback URLs:
http://localhost:3000/api/auth/callback
- Allowed Logout URLs:
http://localhost:3000/
Features
- Written in Typescript
- Uses Auth0
- Simple setup
- Simple API
- Hooks
- SSR support
- Works well with custom APIs
Refresh Tokens
In order to get refresh tokens you need to request the offline_access
scope.
Client API
useSession
getSession
SessionProvider
SessionProvider
allows the user session to be shared across the application and injected on the server-side to avoid loading screens. Highly recommended!
Rest API
/api/auth/login
Query parameters:
redirectTo
: Redirects the user to the provided page. Falls back to the value ofpostLoginRedirectUri
in thenauth0
configuration, and then falls back to/
.
/api/auth/logout
/api/auth/callback
/api/auth/session
Contributing
Contributors ✨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
3 years ago