Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/masfahru/nextjs-dashboard-example-with-authentication
https://github.com/masfahru/nextjs-dashboard-example-with-authentication
next-auth nextjs postgresjs
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/masfahru/nextjs-dashboard-example-with-authentication
- Owner: masfahru
- License: mit
- Created: 2023-11-05T17:26:29.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-07T00:37:55.000Z (about 1 year ago)
- Last Synced: 2024-04-04T10:55:21.741Z (9 months ago)
- Topics: next-auth, nextjs, postgresjs
- Language: TypeScript
- Homepage: https://nextjs.org/learn
- Size: 945 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Next.js 14 App Router Example with Authentication
This is a modified result after following [Next.js learning course](https://nextjs.org/learn)
Tech-stack:
- [Next.js v14](https://github.com/vercel/next.js)
- [Postgres.js v3](https://github.com/porsager/postgres)
- [Nextauth.js v5 (beta)](https://github.com/nextauthjs/next-auth)## Requirements
- Nodejs v20
- Package Manager (npm, yarn, or bun)
- PostgreSQL server (if you want to use local database server)## Development
- Clone this project to local
- Install dependencies: `npm i`
- Copy .env.example to .env
- Modify .env as per the requirement
- Run database seed (just for once): `npm run seed`
- run `npm run dev`## Build
- run `npm run build`
## Start
- run `npm run start` after successful build.
## The changes
There are some differences between the original result of the course and this repository, which are:
### Database driver
Using `Postgres.js` instead of `@vercel/postgres`, both of them have a similiar syntax.
for example:
```javascript
const [result] = sql``;
```### Authentication
Implement a simple session manager, so we can force log-out other sessions by deleting their session id from the database.
Credentials:
```json
{
"email": "[email protected]",
"password": "123456"
}
```### Web Endpoints
- Signin `http://localhost:3000/login`
- Dashboard `http://localhost:3000/dashboard`### RestAPI Endpoints
#### Signin POST `http://localhost:3000/api/auth/callback/credentials`
payload:
```json
{
"email": "[email protected]",
"password": "123456",
"callbackUrl": "/api/auth/session"
}
```**callbackUrl** can be changed to any pathname to redirect after successful sign-in
#### Signout POST `http://localhost:3000/api/auth/signout`
payload:
```json
{
"callbackUrl": "/api/auth/providers"
}
```**callbackUrl** can be changed to any pathname to redirect after successful sign-out