This is a demonstration of Next.js 9 features.
Next.js is a fantastic framework that allows us to build performant server-side rendered React apps with ease.
In this repo, you will find ways how you can utilize the powerful features of Next.js 9, like API routes and Static Site Generation (SSG) to build full-stack React apps.
Also, it use Auth0 to handle user authentication and authorization, and also Chakra UI component library is integrated for better look. into our Next.js project to make it a breeze to build beautiful and modularized user interfaces
To run this project you'll need:
- yarn
- node
or
- docker
If you want try authorisation page please setup
.env
file witAuth0
credentials. See how to do this inAuth0
section.
To start development server simply type following in your terminal:
yarn dev
All other scripts you'll find under Scripts section.
To start production ready server with docker
run:
docker build -t next9 . && docker run -p 3000:3000 --name next9 next9
Now you can open the app in your browser http://localhost:3000/
This section is optional. It's needed to enable a secret page
(protected by auth0
).
Create an env
file with following records, you can get these
here at Application > <Your app>
> Basic Information:
-
AUTH0_DOMAIN
- domain forauth0
server -
AUTH0_CLIENT_ID
- id ofauth0
client; -
AUTH0_CLIENT_SECRET
- secret forauth0
client; -
SESSION_COOKIE_SECRET
- to encrypt cookies. You can generate one withopenssl rand -base64 32
You need also specify Application URIs in Application > <Your app>
> Application URIs.
You will need set Allowed Callback URLs to http://localhost:3000/api/callback
.
Also, we need to set Allowed Logout URLs to http://localhost:3000/secret
There is complete list of all routes:
-
/home
- displays home page -
/about
- displays about page -
/about/me
- displays nested route -
/user/:id
- displays dynamic route whenid
is specified. It also can parse parameters queries. Tryhttp://localhost:3000/user/1?action=create&darkmode=false
or if this
id
doesn't exist you'll become an error. Tryhttp://localhost:3000/user/100?action=create&darkmode=false
-
/secret
- some secret. User needs to be logged in to see it. (Needs.env
file)
There is complete list of all endpoints:
Endpoint | Method | Params | Description |
---|---|---|---|
/api/hello |
GET |
- | Returns hello message |
/api/user/:id |
GET |
id of type Number |
Returns info about user with id |
/api/callback |
GET |
code and state as query |
Handles callback from auth service |
/api/login |
GET |
- | Starts login process |
/api/logout |
GET |
- | Starts logout process |
In the project directory, you can run:
Runs the next app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Builds the next app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified, and the filenames include the hashes.
Your app is ready to be deployed!
Runs the next app in the production mode.
Exports the next app as static version of the site to out
directory.
- React
- Next
- Chakra UI
- SWR
- Auth0
Sierikov Artem – twitter
- Fork it (https://github.com/sierikov/prisma/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request