Skip to content

aidan-neel/auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@aidan-neel/auth

Open-Source TypeScript authentication

NPM @aidan-neel/auth@latest

@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

// 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

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

About

Open-Source TypeScript authentication

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published