@rimelight/auth 0.0.1 → 0.0.3
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/LICENSE +21 -0
- package/dist/adapters/auth0.d.mts +115 -0
- package/dist/adapters/auth0.mjs +256 -0
- package/dist/adapters/cf-access.d.mts +13 -0
- package/dist/adapters/cf-access.mjs +66 -0
- package/dist/adapters/mock.d.mts +9 -0
- package/dist/adapters/mock.mjs +31 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +8 -0
- package/dist/permissions/index.d.mts +47 -0
- package/dist/permissions/index.mjs +83 -0
- package/dist/plugins/construction-guest/index.d.mts +9 -0
- package/dist/plugins/construction-guest/index.mjs +51 -0
- package/dist/plugins/reserved-usernames/index.d.mts +12 -0
- package/dist/plugins/reserved-usernames/index.mjs +192 -0
- package/dist/types.d.mts +58 -0
- package/dist/types.mjs +1 -0
- package/package.json +47 -22
- package/src/client/index.ts +0 -3
- package/src/index.ts +0 -6
- package/src/permissions/index.ts +0 -27
- package/src/plugins/construction-guest/index.ts +0 -107
- package/src/plugins/discriminator-tag/index.ts +0 -55
- package/src/plugins/reserved-usernames/index.ts +0 -198
- package/src/plugins/synthetic-user/index.ts +0 -50
- package/src/schema/drizzle/index.ts +0 -363
- package/src/server/index.ts +0 -148
package/src/server/index.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import type { BetterAuthOptions } from "better-auth"
|
|
2
|
-
import { betterAuth } from "better-auth"
|
|
3
|
-
import { createSyntheticUserWrapper } from "../plugins/synthetic-user"
|
|
4
|
-
import { createTagAndUsernameHook } from "../plugins/discriminator-tag"
|
|
5
|
-
|
|
6
|
-
export interface RimelightAuthFactoryOptions {
|
|
7
|
-
database: BetterAuthOptions["database"]
|
|
8
|
-
db?: any
|
|
9
|
-
userTable?: any
|
|
10
|
-
emailHandlers?: {
|
|
11
|
-
sendVerificationEmail?: (data: any, request?: Request) => Promise<void>
|
|
12
|
-
sendPasswordResetEmail?: (data: any, request?: Request) => Promise<void>
|
|
13
|
-
sendExistingUserSignUpNotification?: (existingUser: any) => Promise<void>
|
|
14
|
-
}
|
|
15
|
-
additionalUserFields?: Record<string, any>
|
|
16
|
-
plugins?: BetterAuthOptions["plugins"]
|
|
17
|
-
statements?: any
|
|
18
|
-
advanced?: BetterAuthOptions["advanced"]
|
|
19
|
-
session?: BetterAuthOptions["session"]
|
|
20
|
-
rateLimit?: BetterAuthOptions["rateLimit"]
|
|
21
|
-
customDatabaseHooks?: BetterAuthOptions["databaseHooks"]
|
|
22
|
-
enableTagGenerator?: boolean
|
|
23
|
-
restrictedUsernameBlacklist?: string[]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function createRimelightAuth(options: RimelightAuthFactoryOptions) {
|
|
27
|
-
const enableTag = options.enableTagGenerator ?? (options.db && options.userTable)
|
|
28
|
-
|
|
29
|
-
const defaultUserHooks =
|
|
30
|
-
enableTag && options.db && options.userTable
|
|
31
|
-
? {
|
|
32
|
-
create: {
|
|
33
|
-
before: createTagAndUsernameHook(options.db, options.userTable)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
: undefined
|
|
37
|
-
|
|
38
|
-
const emailAndPasswordConfig: BetterAuthOptions["emailAndPassword"] = {
|
|
39
|
-
enabled: true,
|
|
40
|
-
autoSignIn: false,
|
|
41
|
-
requireEmailVerification: true,
|
|
42
|
-
minPasswordLength: 8,
|
|
43
|
-
maxPasswordLength: 128,
|
|
44
|
-
customSyntheticUser: createSyntheticUserWrapper
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (options.emailHandlers?.sendPasswordResetEmail) {
|
|
48
|
-
emailAndPasswordConfig.sendResetPassword = options.emailHandlers.sendPasswordResetEmail
|
|
49
|
-
}
|
|
50
|
-
if (options.emailHandlers?.sendExistingUserSignUpNotification) {
|
|
51
|
-
const handler = options.emailHandlers.sendExistingUserSignUpNotification
|
|
52
|
-
emailAndPasswordConfig.onExistingUserSignUp = async (existingUser: any) => {
|
|
53
|
-
await handler(existingUser)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const emailVerificationConfig: BetterAuthOptions["emailVerification"] = {
|
|
58
|
-
autoSignInAfterVerification: true
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (options.emailHandlers?.sendVerificationEmail) {
|
|
62
|
-
emailVerificationConfig.sendVerificationEmail = options.emailHandlers.sendVerificationEmail
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return betterAuth({
|
|
66
|
-
database: options.database,
|
|
67
|
-
emailAndPassword: emailAndPasswordConfig,
|
|
68
|
-
emailVerification: emailVerificationConfig,
|
|
69
|
-
user: {
|
|
70
|
-
changeEmail: {
|
|
71
|
-
enabled: true
|
|
72
|
-
},
|
|
73
|
-
deleteUser: {
|
|
74
|
-
enabled: true
|
|
75
|
-
},
|
|
76
|
-
additionalFields: {
|
|
77
|
-
tag: {
|
|
78
|
-
type: "string",
|
|
79
|
-
required: false,
|
|
80
|
-
input: false
|
|
81
|
-
},
|
|
82
|
-
firstName: {
|
|
83
|
-
type: "string",
|
|
84
|
-
required: true,
|
|
85
|
-
default: "",
|
|
86
|
-
input: true
|
|
87
|
-
},
|
|
88
|
-
lastName: {
|
|
89
|
-
type: "string",
|
|
90
|
-
required: true,
|
|
91
|
-
default: "",
|
|
92
|
-
input: true
|
|
93
|
-
},
|
|
94
|
-
role: {
|
|
95
|
-
type: "string",
|
|
96
|
-
required: false,
|
|
97
|
-
default: "user",
|
|
98
|
-
input: false
|
|
99
|
-
},
|
|
100
|
-
availability: {
|
|
101
|
-
type: "string",
|
|
102
|
-
required: false,
|
|
103
|
-
default: "available"
|
|
104
|
-
},
|
|
105
|
-
status: {
|
|
106
|
-
type: "string",
|
|
107
|
-
required: false,
|
|
108
|
-
default: ""
|
|
109
|
-
},
|
|
110
|
-
publicKey: {
|
|
111
|
-
type: "string",
|
|
112
|
-
required: false,
|
|
113
|
-
input: true
|
|
114
|
-
},
|
|
115
|
-
...options.additionalUserFields
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
session: {
|
|
119
|
-
expiresIn: 60 * 60 * 24 * 7,
|
|
120
|
-
updateAge: 60 * 60 * 24,
|
|
121
|
-
freshAge: 60 * 15,
|
|
122
|
-
cookieCache: {
|
|
123
|
-
enabled: true,
|
|
124
|
-
maxAge: 60 * 5
|
|
125
|
-
},
|
|
126
|
-
...options.session
|
|
127
|
-
},
|
|
128
|
-
rateLimit: {
|
|
129
|
-
window: 10,
|
|
130
|
-
max: 100,
|
|
131
|
-
storage: "database",
|
|
132
|
-
modelName: "rateLimit",
|
|
133
|
-
...options.rateLimit
|
|
134
|
-
},
|
|
135
|
-
plugins: options.plugins ?? [],
|
|
136
|
-
auth: options.statements ? { statements: options.statements } : undefined,
|
|
137
|
-
advanced: {
|
|
138
|
-
useSecureCookies: process.env.NODE_ENV === "production",
|
|
139
|
-
cookiePrefix: "auth",
|
|
140
|
-
database: {
|
|
141
|
-
generateId: () => crypto.randomUUID()
|
|
142
|
-
},
|
|
143
|
-
...options.advanced
|
|
144
|
-
},
|
|
145
|
-
databaseHooks:
|
|
146
|
-
options.customDatabaseHooks ?? (defaultUserHooks ? { user: defaultUserHooks } : undefined)
|
|
147
|
-
})
|
|
148
|
-
}
|