@ofeklabs/horizon-auth 1.0.5 → 1.0.7
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/README.md +133 -0
- package/dist/auth/auth.module.js +2 -0
- package/dist/auth/auth.module.js.map +1 -1
- package/dist/auth/auth.service.d.ts +3 -1
- package/dist/auth/auth.service.js +15 -3
- package/dist/auth/auth.service.js.map +1 -1
- package/dist/auth/services/email.service.d.ts +15 -0
- package/dist/auth/services/email.service.js +168 -0
- package/dist/auth/services/email.service.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +9 -1
- package/prisma/README.md +143 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ofeklabs/horizon-auth",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Production-ready NestJS authentication module with 2FA, device management, push notifications, and account management",
|
|
5
5
|
"author": "Ofek Itzhaki",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,6 +34,14 @@
|
|
|
34
34
|
"reflect-metadata": "^0.1.13",
|
|
35
35
|
"rxjs": "^7.8.0"
|
|
36
36
|
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"resend": {
|
|
39
|
+
"optional": true
|
|
40
|
+
},
|
|
41
|
+
"@sendgrid/mail": {
|
|
42
|
+
"optional": true
|
|
43
|
+
}
|
|
44
|
+
},
|
|
37
45
|
"dependencies": {
|
|
38
46
|
"@nestjs/jwt": "^10.2.0",
|
|
39
47
|
"@nestjs/throttler": "^5.1.0",
|
package/prisma/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Prisma Schema for @ofeklabs/horizon-auth
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This directory contains the Prisma schema required by the @ofeklabs/horizon-auth package. Your application MUST include these models in its own `schema.prisma` file.
|
|
6
|
+
|
|
7
|
+
## Required Setup
|
|
8
|
+
|
|
9
|
+
### Step 1: Copy Models to Your Schema
|
|
10
|
+
|
|
11
|
+
Copy all models from `schema.prisma` in this directory to your application's `prisma/schema.prisma` file.
|
|
12
|
+
|
|
13
|
+
**IMPORTANT**: Merge the models - don't replace your entire schema!
|
|
14
|
+
|
|
15
|
+
### Step 2: Generate Prisma Client
|
|
16
|
+
|
|
17
|
+
After adding the models, regenerate your Prisma Client:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx prisma generate
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Step 3: Run Migrations
|
|
24
|
+
|
|
25
|
+
Create and apply the database migration:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx prisma migrate dev --name add-horizon-auth-models
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Required Models
|
|
32
|
+
|
|
33
|
+
The package requires these models to function:
|
|
34
|
+
|
|
35
|
+
### Core Models (Always Required)
|
|
36
|
+
- **User** - Core user authentication and profile
|
|
37
|
+
- **RefreshToken** - JWT refresh token storage with rotation
|
|
38
|
+
|
|
39
|
+
### Feature-Specific Models (Required if feature is enabled)
|
|
40
|
+
- **SocialAccount** - OAuth social login (Google, Facebook)
|
|
41
|
+
- **Device** - Device management and tracking
|
|
42
|
+
- **PushToken** - Push notification token storage
|
|
43
|
+
- **TwoFactorAuth** - TOTP 2FA secrets
|
|
44
|
+
- **BackupCode** - 2FA backup codes
|
|
45
|
+
|
|
46
|
+
## Model Relationships
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
User
|
|
50
|
+
├── RefreshToken[] (one-to-many)
|
|
51
|
+
├── SocialAccount[] (one-to-many)
|
|
52
|
+
├── Device[] (one-to-many)
|
|
53
|
+
├── PushToken[] (one-to-many)
|
|
54
|
+
├── TwoFactorAuth? (one-to-one)
|
|
55
|
+
└── BackupCode[] (one-to-many)
|
|
56
|
+
|
|
57
|
+
Device
|
|
58
|
+
├── RefreshToken[] (one-to-many)
|
|
59
|
+
└── PushToken[] (one-to-many)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Customization
|
|
63
|
+
|
|
64
|
+
You can customize the models to fit your needs:
|
|
65
|
+
|
|
66
|
+
### Adding Fields
|
|
67
|
+
You can add additional fields to any model:
|
|
68
|
+
|
|
69
|
+
```prisma
|
|
70
|
+
model User {
|
|
71
|
+
// ... existing fields from horizon-auth
|
|
72
|
+
|
|
73
|
+
// Your custom fields
|
|
74
|
+
phoneNumber String?
|
|
75
|
+
avatar String?
|
|
76
|
+
preferences Json?
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Changing Table Names
|
|
81
|
+
The `@@map()` directive controls the database table name:
|
|
82
|
+
|
|
83
|
+
```prisma
|
|
84
|
+
model User {
|
|
85
|
+
// ...
|
|
86
|
+
@@map("users") // Table name in database
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Adding Relations
|
|
91
|
+
You can add relations to your own models:
|
|
92
|
+
|
|
93
|
+
```prisma
|
|
94
|
+
model User {
|
|
95
|
+
// ... existing fields from horizon-auth
|
|
96
|
+
|
|
97
|
+
// Your custom relations
|
|
98
|
+
orders Order[]
|
|
99
|
+
profile UserProfile?
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Multi-Tenant Support
|
|
104
|
+
|
|
105
|
+
The User model includes a `tenantId` field for multi-tenant applications. If you're not using multi-tenancy, you can:
|
|
106
|
+
|
|
107
|
+
1. Keep the field (it defaults to "default")
|
|
108
|
+
2. Remove the field and related indexes (requires modifying the package's services)
|
|
109
|
+
|
|
110
|
+
## Database Support
|
|
111
|
+
|
|
112
|
+
The schema is designed for PostgreSQL but can be adapted for other databases:
|
|
113
|
+
|
|
114
|
+
- **PostgreSQL** - Fully supported (recommended)
|
|
115
|
+
- **MySQL** - Supported (change `@default(cuid())` to `@default(uuid())`)
|
|
116
|
+
- **SQLite** - Supported for development (not recommended for production)
|
|
117
|
+
- **MongoDB** - Not supported (package uses relational features)
|
|
118
|
+
|
|
119
|
+
## Troubleshooting
|
|
120
|
+
|
|
121
|
+
### Error: "Cannot read properties of undefined (reading 'findUnique')"
|
|
122
|
+
|
|
123
|
+
**Cause**: The User model is missing from your schema.
|
|
124
|
+
|
|
125
|
+
**Solution**: Copy all models from this schema to your application's schema.
|
|
126
|
+
|
|
127
|
+
### Error: "Invalid `prisma.user.findUnique()` invocation"
|
|
128
|
+
|
|
129
|
+
**Cause**: Prisma Client wasn't regenerated after adding models.
|
|
130
|
+
|
|
131
|
+
**Solution**: Run `npx prisma generate` and restart your application.
|
|
132
|
+
|
|
133
|
+
### Error: "Unknown field 'emailVerifyToken' on model 'User'"
|
|
134
|
+
|
|
135
|
+
**Cause**: Your User model is missing required fields.
|
|
136
|
+
|
|
137
|
+
**Solution**: Ensure you copied the complete User model definition, not just the model name.
|
|
138
|
+
|
|
139
|
+
## Need Help?
|
|
140
|
+
|
|
141
|
+
- Check the [Migration Guide](../MIGRATION.md)
|
|
142
|
+
- Review the [Main README](../README.md)
|
|
143
|
+
- Open an issue on GitHub
|