@factiii/auth 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,104 @@
1
+ {
2
+ "name": "@factiii/auth",
3
+ "version": "0.1.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "Authentication library for tRPC with JWT, OAuth, 2FA, and session management from factiii.",
8
+ "author": "Factiii",
9
+ "license": "MIT",
10
+ "keywords": [
11
+ "auth",
12
+ "authentication",
13
+ "trpc",
14
+ "jwt",
15
+ "oauth",
16
+ "2fa",
17
+ "totp",
18
+ "session",
19
+ "prisma",
20
+ "typescript"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/factiii/auth.git"
25
+ },
26
+ "main": "./dist/index.js",
27
+ "module": "./dist/index.mjs",
28
+ "types": "./dist/index.d.ts",
29
+ "sideEffects": false,
30
+ "bin": {
31
+ "factiii-auth": "bin/init.mjs"
32
+ },
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.mjs",
37
+ "require": "./dist/index.js"
38
+ },
39
+ "./validators": {
40
+ "types": "./dist/validators.d.ts",
41
+ "import": "./dist/validators.mjs",
42
+ "require": "./dist/validators.js"
43
+ },
44
+ "./prisma/schema.prisma": "./prisma/schema.prisma"
45
+ },
46
+ "files": [
47
+ "bin",
48
+ "dist",
49
+ "prisma",
50
+ "README.md"
51
+ ],
52
+ "scripts": {
53
+ "build": "tsup",
54
+ "dev": "tsup --watch",
55
+ "check-types": "tsc --noEmit",
56
+ "lint": "eslint src --ext .ts,.tsx",
57
+ "lint:fix": "eslint src --ext .ts,.tsx --fix",
58
+ "clean": "rm -rf dist node_modules/.cache .turbo",
59
+ "prepublishOnly": "npm run build"
60
+ },
61
+ "dependencies": {
62
+ "@trpc/server": "11.8.0",
63
+ "apple-signin-auth": "^2.0.0",
64
+ "bcryptjs": "^2.4.3",
65
+ "google-auth-library": "^10.5.0",
66
+ "jsonwebtoken": "^9.0.2",
67
+ "totp-generator": "^2.0.0"
68
+ },
69
+ "peerDependencies": {
70
+ "@prisma/client": ">=5.0.0",
71
+ "superjson": ">=1.0.0",
72
+ "zod": ">=3.20.0"
73
+ },
74
+ "peerDependenciesMeta": {
75
+ "@prisma/client": {
76
+ "optional": false
77
+ },
78
+ "superjson": {
79
+ "optional": false
80
+ },
81
+ "zod": {
82
+ "optional": false
83
+ }
84
+ },
85
+ "devDependencies": {
86
+ "@prisma/client": "^7.1.0",
87
+ "@trpc/server": "11.8.0",
88
+ "@types/bcryptjs": "^2.4.6",
89
+ "@types/jsonwebtoken": "^9.0.9",
90
+ "@types/node": "^20.19.0",
91
+ "@typescript-eslint/eslint-plugin": "^7.18.0",
92
+ "@typescript-eslint/parser": "^7.18.0",
93
+ "eslint": "^8.57.0",
94
+ "prisma": "^7.1.0",
95
+ "superjson": "^1.13.3",
96
+ "tsup": "^8.3.5",
97
+ "typescript": "5.9.3",
98
+ "zod": "3.24.2"
99
+ },
100
+ "engines": {
101
+ "node": ">=18.0.0"
102
+ },
103
+ "packageManager": "pnpm@10.26.0+sha512.3b3f6c725ebe712506c0ab1ad4133cf86b1f4b687effce62a9b38b4d72e3954242e643190fc51fa1642949c735f403debd44f5cb0edd657abe63a8b6a7e1e402"
104
+ }
@@ -0,0 +1,138 @@
1
+ // ==============================================================================
2
+ // Auth Schema
3
+ // ==============================================================================
4
+
5
+ generator client {
6
+ provider = "prisma-client-js"
7
+ }
8
+
9
+ datasource db {
10
+ provider = "postgresql"
11
+ }
12
+
13
+ // ==============================================================================
14
+ // Enums
15
+ // ==============================================================================
16
+
17
+ enum UserStatus {
18
+ ACTIVE
19
+ DEACTIVATED
20
+ BANNED
21
+ }
22
+
23
+ enum UserTag {
24
+ HUMAN
25
+ BOT
26
+ }
27
+
28
+ enum EmailVerificationStatus {
29
+ UNVERIFIED
30
+ PENDING
31
+ VERIFIED
32
+ }
33
+
34
+ enum OAuthProvider {
35
+ GOOGLE
36
+ APPLE
37
+ }
38
+
39
+ // ==============================================================================
40
+ // User Model
41
+ // ==============================================================================
42
+
43
+ model User {
44
+ id Int @id @default(autoincrement())
45
+ createdAt DateTime @default(now())
46
+ status UserStatus @default(ACTIVE)
47
+ email String @unique
48
+ emailVerificationStatus EmailVerificationStatus @default(UNVERIFIED)
49
+ password String?
50
+ username String @unique
51
+ twoFaEnabled Boolean @default(false)
52
+ oauthProvider OAuthProvider?
53
+ oauthId String?
54
+ tag UserTag @default(HUMAN)
55
+ isActive Boolean @default(false)
56
+ verifiedHumanAt DateTime?
57
+ otpForEmailVerification String?
58
+
59
+ // Relations
60
+ sessions Session[]
61
+ passwordReset PasswordReset[]
62
+ otpsForLogin OTPBasedLogin[]
63
+ devices Device[] @relation("devices")
64
+ admin Admin?
65
+ }
66
+
67
+ // ==============================================================================
68
+ // Session Model
69
+ // ==============================================================================
70
+
71
+ model Session {
72
+ id Int @id @default(autoincrement())
73
+ socketId String? @unique
74
+ twoFaSecret String? @unique
75
+ refreshToken String? @unique
76
+ issuedAt DateTime @default(now())
77
+ browserName String @default("Unknown")
78
+ lastUsed DateTime @default(now()) @updatedAt
79
+ device Device? @relation(fields: [deviceId], references: [id])
80
+ deviceId Int?
81
+ userId Int
82
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
83
+ revokedAt DateTime?
84
+
85
+ @@index([userId])
86
+ @@index([deviceId])
87
+ }
88
+
89
+ // ==============================================================================
90
+ // Admin Model
91
+ // ==============================================================================
92
+
93
+ model Admin {
94
+ ip String
95
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
96
+ userId Int @unique
97
+
98
+ @@id([userId])
99
+ }
100
+
101
+ // ==============================================================================
102
+ // PasswordReset Model
103
+ // ==============================================================================
104
+
105
+ model PasswordReset {
106
+ id String @id @default(uuid())
107
+ createdAt DateTime @default(now())
108
+ userId Int
109
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
110
+ invalidatedAt DateTime?
111
+
112
+ @@index([userId])
113
+ }
114
+
115
+ // ==============================================================================
116
+ // OTPBasedLogin Model
117
+ // ==============================================================================
118
+
119
+ model OTPBasedLogin {
120
+ id Int @id @default(autoincrement())
121
+ code Int
122
+ userId Int
123
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
124
+ createdAt DateTime @default(now())
125
+ disabled Boolean @default(false)
126
+ }
127
+
128
+ // ==============================================================================
129
+ // Device Model
130
+ // ==============================================================================
131
+
132
+ model Device {
133
+ id Int @id @default(autoincrement())
134
+ pushToken String @unique
135
+ createdAt DateTime @default(now())
136
+ users User[] @relation("devices")
137
+ sessions Session[]
138
+ }