@authcore/core 0.5.0 → 0.5.2
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 +114 -0
- package/dist/utils/password.js +1 -1
- package/dist/utils/password.js.map +1 -1
- package/package.json +5 -4
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# @authcore/core
|
|
2
|
+
|
|
3
|
+
> Framework-agnostic authentication engine — types, validation, password hashing, JWT, and adapter interfaces.
|
|
4
|
+
|
|
5
|
+
This is the core package that powers all AuthCore framework adapters. You typically won't use it directly — instead, use [`@authcore/express`](https://www.npmjs.com/package/@authcore/express) or [`@authcore/fastify`](https://www.npmjs.com/package/@authcore/fastify).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @authcore/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## What's Inside
|
|
14
|
+
|
|
15
|
+
### `createAuth(config)`
|
|
16
|
+
|
|
17
|
+
The main factory that creates an auth instance with `register`, `login`, `verifyToken`, `verifyEmail`, `forgotPassword`, and `resetPassword` methods.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { createAuth } from '@authcore/core'
|
|
21
|
+
|
|
22
|
+
const auth = createAuth({
|
|
23
|
+
db: myDatabaseAdapter,
|
|
24
|
+
session: { strategy: 'jwt', secret: 'your-secret', expiresIn: '7d' },
|
|
25
|
+
email: { provider: myEmailAdapter, from: 'auth@example.com' },
|
|
26
|
+
features: ['emailVerification', 'passwordReset'],
|
|
27
|
+
password: { minLength: 8 },
|
|
28
|
+
callbacks: {
|
|
29
|
+
onSignUp: (user) => { /* ... */ },
|
|
30
|
+
onSignIn: (user) => { /* ... */ },
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const { user, token } = await auth.register({ email: 'user@example.com', password: 'securepass' })
|
|
35
|
+
const { user, token } = await auth.login({ email: 'user@example.com', password: 'securepass' })
|
|
36
|
+
const publicUser = await auth.verifyToken(token)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Adapter Interfaces
|
|
40
|
+
|
|
41
|
+
Implement these to add support for any database or email provider:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import type { DatabaseAdapter, EmailAdapter } from '@authcore/core'
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**DatabaseAdapter:**
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
interface DatabaseAdapter {
|
|
51
|
+
findUserByEmail(email: string): Promise<User | null>
|
|
52
|
+
findUserById(id: string): Promise<User | null>
|
|
53
|
+
createUser(data: CreateUserInput): Promise<User>
|
|
54
|
+
updateUser(id: string, data: Partial<User>): Promise<User>
|
|
55
|
+
createToken(data: CreateTokenInput): Promise<Token>
|
|
56
|
+
findToken(rawToken: string, type: TokenType): Promise<Token | null>
|
|
57
|
+
deleteToken(id: string): Promise<void>
|
|
58
|
+
deleteExpiredTokens(): Promise<void>
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**EmailAdapter:**
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
interface EmailAdapter {
|
|
66
|
+
send(options: { from: string; to: string; subject: string; html: string; text: string }): Promise<void>
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Types
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import type {
|
|
74
|
+
User,
|
|
75
|
+
PublicUser,
|
|
76
|
+
Token,
|
|
77
|
+
TokenType,
|
|
78
|
+
AuthCoreConfig,
|
|
79
|
+
AuthCore,
|
|
80
|
+
DatabaseAdapter,
|
|
81
|
+
EmailAdapter,
|
|
82
|
+
AuthError,
|
|
83
|
+
} from '@authcore/core'
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Utilities
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import {
|
|
90
|
+
hashPassword,
|
|
91
|
+
verifyPassword,
|
|
92
|
+
generateOpaqueToken,
|
|
93
|
+
hashToken,
|
|
94
|
+
safeCompareTokens,
|
|
95
|
+
signJwt,
|
|
96
|
+
verifyJwt,
|
|
97
|
+
} from '@authcore/core'
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Validation Schemas (Zod)
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import {
|
|
104
|
+
registerSchema,
|
|
105
|
+
loginSchema,
|
|
106
|
+
forgotPasswordSchema,
|
|
107
|
+
resetPasswordSchema,
|
|
108
|
+
verifyEmailSchema,
|
|
109
|
+
} from '@authcore/core'
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
[MIT](https://github.com/david-ouatedem/auth-core/blob/main/LICENSE)
|
package/dist/utils/password.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password.js","sourceRoot":"","sources":["../../src/utils/password.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"password.js","sourceRoot":"","sources":["../../src/utils/password.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAA;AAE7B,MAAM,mBAAmB,GAAG,EAAE,CAAA;AAE9B;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAAgB,EAChB,aAAqB,mBAAmB;IAExC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAA;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;AACtC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,QAAgB,EAAE,IAAY;IACjE,OAAO,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;AACvC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authcore/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Framework-agnostic authentication core for AuthCore",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "David Ouatedem",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"bcrypt"
|
|
18
18
|
],
|
|
19
19
|
"files": [
|
|
20
|
-
"dist"
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
21
22
|
],
|
|
22
23
|
"publishConfig": {
|
|
23
24
|
"access": "public"
|
|
@@ -32,12 +33,12 @@
|
|
|
32
33
|
}
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
|
-
"
|
|
36
|
+
"bcryptjs": "^2.4.3",
|
|
36
37
|
"jsonwebtoken": "^9.0.2",
|
|
37
38
|
"zod": "^3.23.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@types/
|
|
41
|
+
"@types/bcryptjs": "^2.4.0",
|
|
41
42
|
"@types/jsonwebtoken": "^9.0.6",
|
|
42
43
|
"@types/node": "^20.0.0",
|
|
43
44
|
"typescript": "^5.4.0",
|