@ofeklabs/horizon-auth 1.0.4 → 1.0.6
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 +66 -0
- package/dist/auth/auth.service.d.ts +1 -1
- package/dist/auth/auth.service.js +4 -1
- package/dist/auth/auth.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/users/users.service.js +8 -0
- package/dist/users/users.service.js.map +1 -1
- package/package.json +1 -1
- package/prisma/README.md +143 -0
|
@@ -20,6 +20,9 @@ const constants_1 = require("../common/constants");
|
|
|
20
20
|
let UsersService = class UsersService {
|
|
21
21
|
constructor(prisma) {
|
|
22
22
|
this.prisma = prisma;
|
|
23
|
+
console.log('🔍 UsersService constructor - prisma type:', prisma?.constructor?.name);
|
|
24
|
+
console.log('🔍 UsersService constructor - prisma defined:', !!prisma);
|
|
25
|
+
console.log('🔍 UsersService constructor - this.prisma defined:', !!this.prisma);
|
|
23
26
|
if (!this.prisma) {
|
|
24
27
|
throw new Error(`PRISMA_CLIENT_TOKEN injection failed in UsersService. ` +
|
|
25
28
|
`Token value: "${constants_1.PRISMA_CLIENT_TOKEN}". ` +
|
|
@@ -27,6 +30,11 @@ let UsersService = class UsersService {
|
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
async findByEmail(email) {
|
|
33
|
+
console.log('🔍 findByEmail called - this.prisma defined:', !!this.prisma);
|
|
34
|
+
console.log('🔍 findByEmail called - this.prisma type:', this.prisma?.constructor?.name);
|
|
35
|
+
if (!this.prisma) {
|
|
36
|
+
throw new Error('RUNTIME ERROR: this.prisma is undefined in findByEmail!');
|
|
37
|
+
}
|
|
30
38
|
return this.prisma.user.findUnique({
|
|
31
39
|
where: { email },
|
|
32
40
|
include: { refreshTokens: true },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.service.js","sourceRoot":"","sources":["../../src/users/users.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;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IAAI,CAAC,MAAM,CAAC;YAC7B,KAAK,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE;YACtB,IAAI,EAAE;gBACJ,YAAY,EAAE,eAAe;gBAC7B,UAAU,EAAE,IAAI;gBAChB,gBAAgB,EAAE,IAAI;aACvB;SACF,CAAC,CAAC;IACL,CAAC;IAOD,UAAU,CAAC,IAAU;QACnB,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI,CAAC;QAC3F,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAA;AA3KY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;IAIE,WAAA,IAAA,eAAM,EAAC,+BAAmB,CAAC,CAAA;qCAAS,qBAAY;GAHlD,YAAY,CA2KxB"}
|
package/package.json
CHANGED
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
|