https://github.com/aidan-neel/auth
Open-Source TypeScript authentication
https://github.com/aidan-neel/auth
auth authentication authorization javascript typecsript
Last synced: 4 months ago
JSON representation
Open-Source TypeScript authentication
- Host: GitHub
- URL: https://github.com/aidan-neel/auth
- Owner: aidan-neel
- License: mit
- Created: 2025-03-09T05:54:36.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-27T00:23:45.000Z (about 1 year ago)
- Last Synced: 2025-09-20T20:42:17.282Z (9 months ago)
- Topics: auth, authentication, authorization, javascript, typecsript
- Language: TypeScript
- Homepage:
- Size: 48.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## @aidan-neel/auth
Open-Source TypeScript authentication

`@aidan-neel/auth` implements JWT-based authentication for support with Prisma ORM seamlessly.
## Setup
#### Prisma
Add the following lines to your `schema.prisma` file and install the prisma adapter
```prisma
// You can add anything else to it but these 6 are required
model User {
id Int @id @default(autoincrement())
email String @unique
username String
password String
refreshTokens RefreshToken[]
@@map("users")
}
model RefreshToken {
id Int @id @default(autoincrement())
token String @unique
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int @map("user_id")
expiresAt DateTime @map("expires_at")
@@map("refresh_tokens")
}
```
## Install
`npm install @aidan-neel/auth`
## Usage
#### Example with Prisma
Install the adapter
`npm install @aidan-neel/auth-prisma`
```js
import { Auth } from "@aidan-neel/auth";
import { PrismaAdapter } from "@aidan-neel/auth-prisma";
import { PrismaClient } from "@prisma/client";
const Prisma = new PrismaClient();
const auth = new Auth({
adapter: new PrismaAdapter(Prisma),
});
// Register
await auth.registerUser(email, password);
// Login
const { access_token, refresh_token } = await auth.loginUser(email, password);
// Refresh Access Token
const { refreshed_access_token, refreshed_token } =
await auth.refreshAccessToken(refresh_token);
// Logout
await auth.logoutUser(refreshed_token);
```
## Adapters
- `@aidan-neel/auth-postgresql`
- `@aidan-neel/auth-prisma`