https://github.com/baybreezy/nitro-passport-jwt-example
This repo serves as an example of how you can implement Passport.js with JWT in a Nitro API. For database operations, Prisma is used. The example uses PostgreSQL as the database but you can use any other database supported by Prisma.
https://github.com/baybreezy/nitro-passport-jwt-example
h3 nitro-js passport-jwt passportjs
Last synced: 4 months ago
JSON representation
This repo serves as an example of how you can implement Passport.js with JWT in a Nitro API. For database operations, Prisma is used. The example uses PostgreSQL as the database but you can use any other database supported by Prisma.
- Host: GitHub
- URL: https://github.com/baybreezy/nitro-passport-jwt-example
- Owner: BayBreezy
- Created: 2024-09-06T16:20:39.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-12-23T14:44:48.000Z (5 months ago)
- Last Synced: 2024-12-23T15:34:44.432Z (5 months ago)
- Topics: h3, nitro-js, passport-jwt, passportjs
- Language: TypeScript
- Homepage:
- Size: 1.09 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Nitro Passport JWT Example ft Prisma
This repository contains an example of how to use Passport.js with JWT strategy in a Nitro project. The example uses Prisma as the ORM.
## Getting Started
- Clone the repository
- Make a copy of `.env.example` and rename it to `.env`
- Fill out the environment variables in the `.env` file
- Run `npm install`
- **Optionally** run the seed command `npm run prisma:seed`
- Run the server `npm run dev`## Noteworthy
- Check out the [Passport Init Plugin File](./server/plugins/init-passport.ts) to see how Passport is initialized in the project. Take note of the `fromNodeMiddleware` utility function that is used to convert the Passport middleware to one that can be used by Nitro.
- Checkout the [Prisma Initialization File](./server/utils/prisma.ts) to see how Prisma is initialized in the project. The `prisma` instance can be automatically imported into any file in the project.
- Checkout the [Passport Configuration File](./server/utils/passport.ts) to see how the Passport strategies are configured in the project.
- Checkout the [Required Auth File](./server/utils/requireJwtAuth.ts). This event handler is used to protect routes that require authentication. Use it in the `onRequest` array inside your event handlers.