@softure-ai/auth 0.0.0-stage → 0.1.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/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +490 -2
- package/dist/contract.d.ts +46 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +2 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +194 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/dist/mailing/index.d.ts +2 -0
- package/dist/mailing/index.d.ts.map +1 -0
- package/dist/mailing/index.js +4 -0
- package/dist/mailing/index.js.map +1 -0
- package/dist/mailing/reset-mail.d.ts +27 -0
- package/dist/mailing/reset-mail.d.ts.map +1 -0
- package/dist/mailing/reset-mail.js +55 -0
- package/dist/mailing/reset-mail.js.map +1 -0
- package/dist/messages/en.d.ts +98 -0
- package/dist/messages/en.d.ts.map +1 -0
- package/dist/messages/en.js +93 -0
- package/dist/messages/en.js.map +1 -0
- package/dist/messages/index.d.ts +201 -0
- package/dist/messages/index.d.ts.map +1 -0
- package/dist/messages/index.js +11 -0
- package/dist/messages/index.js.map +1 -0
- package/dist/messages/pl.d.ts +3 -0
- package/dist/messages/pl.d.ts.map +1 -0
- package/dist/messages/pl.js +92 -0
- package/dist/messages/pl.js.map +1 -0
- package/dist/next/actions.d.ts +19 -0
- package/dist/next/actions.d.ts.map +1 -0
- package/dist/next/actions.js +231 -0
- package/dist/next/actions.js.map +1 -0
- package/dist/next/context.d.ts +4 -0
- package/dist/next/context.d.ts.map +1 -0
- package/dist/next/context.js +13 -0
- package/dist/next/context.js.map +1 -0
- package/dist/next/current-user.d.ts +34 -0
- package/dist/next/current-user.d.ts.map +1 -0
- package/dist/next/current-user.js +77 -0
- package/dist/next/current-user.js.map +1 -0
- package/dist/next/index.d.ts +8 -0
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/index.js +9 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/logout-button.d.ts +7 -0
- package/dist/next/logout-button.d.ts.map +1 -0
- package/dist/next/logout-button.js +12 -0
- package/dist/next/logout-button.js.map +1 -0
- package/dist/next/messages.d.ts +5 -0
- package/dist/next/messages.d.ts.map +1 -0
- package/dist/next/messages.js +7 -0
- package/dist/next/messages.js.map +1 -0
- package/dist/next/pages.d.ts +31 -0
- package/dist/next/pages.d.ts.map +1 -0
- package/dist/next/pages.js +118 -0
- package/dist/next/pages.js.map +1 -0
- package/dist/next/params.d.ts +3 -0
- package/dist/next/params.d.ts.map +1 -0
- package/dist/next/params.js +4 -0
- package/dist/next/params.js.map +1 -0
- package/dist/next/route.d.ts +3 -0
- package/dist/next/route.d.ts.map +1 -0
- package/dist/next/route.js +17 -0
- package/dist/next/route.js.map +1 -0
- package/dist/next/search-params.d.ts +5 -0
- package/dist/next/search-params.d.ts.map +1 -0
- package/dist/next/search-params.js +13 -0
- package/dist/next/search-params.js.map +1 -0
- package/dist/next/session-cookie.d.ts +11 -0
- package/dist/next/session-cookie.d.ts.map +1 -0
- package/dist/next/session-cookie.js +71 -0
- package/dist/next/session-cookie.js.map +1 -0
- package/dist/options.d.ts +72 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +115 -0
- package/dist/options.js.map +1 -0
- package/dist/password-reset-sender.d.ts +21 -0
- package/dist/password-reset-sender.d.ts.map +1 -0
- package/dist/password-reset-sender.js +12 -0
- package/dist/password-reset-sender.js.map +1 -0
- package/dist/proxy/index.d.ts +14 -0
- package/dist/proxy/index.d.ts.map +1 -0
- package/dist/proxy/index.js +59 -0
- package/dist/proxy/index.js.map +1 -0
- package/dist/redirect-target.d.ts +7 -0
- package/dist/redirect-target.d.ts.map +1 -0
- package/dist/redirect-target.js +25 -0
- package/dist/redirect-target.js.map +1 -0
- package/dist/roles.d.ts +5 -0
- package/dist/roles.d.ts.map +1 -0
- package/dist/roles.js +6 -0
- package/dist/roles.js.map +1 -0
- package/dist/safe-next-path.d.ts +5 -0
- package/dist/safe-next-path.d.ts.map +1 -0
- package/dist/safe-next-path.js +25 -0
- package/dist/safe-next-path.js.map +1 -0
- package/dist/schema.d.ts +302 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +37 -0
- package/dist/schema.js.map +1 -0
- package/dist/scripts/index.d.ts +3 -0
- package/dist/scripts/index.d.ts.map +1 -0
- package/dist/scripts/index.js +5 -0
- package/dist/scripts/index.js.map +1 -0
- package/dist/scripts/role-scripts.d.ts +15 -0
- package/dist/scripts/role-scripts.d.ts.map +1 -0
- package/dist/scripts/role-scripts.js +76 -0
- package/dist/scripts/role-scripts.js.map +1 -0
- package/dist/scripts/temporary-password.d.ts +12 -0
- package/dist/scripts/temporary-password.d.ts.map +1 -0
- package/dist/scripts/temporary-password.js +47 -0
- package/dist/scripts/temporary-password.js.map +1 -0
- package/dist/server/change-password.d.ts +14 -0
- package/dist/server/change-password.d.ts.map +1 -0
- package/dist/server/change-password.js +50 -0
- package/dist/server/change-password.js.map +1 -0
- package/dist/server/health.d.ts +3 -0
- package/dist/server/health.d.ts.map +1 -0
- package/dist/server/health.js +15 -0
- package/dist/server/health.js.map +1 -0
- package/dist/server/index.d.ts +12 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +14 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/login.d.ts +14 -0
- package/dist/server/login.d.ts.map +1 -0
- package/dist/server/login.js +50 -0
- package/dist/server/login.js.map +1 -0
- package/dist/server/options.d.ts +19 -0
- package/dist/server/options.d.ts.map +1 -0
- package/dist/server/options.js +50 -0
- package/dist/server/options.js.map +1 -0
- package/dist/server/password-reset.d.ts +54 -0
- package/dist/server/password-reset.d.ts.map +1 -0
- package/dist/server/password-reset.js +134 -0
- package/dist/server/password-reset.js.map +1 -0
- package/dist/server/password.d.ts +25 -0
- package/dist/server/password.d.ts.map +1 -0
- package/dist/server/password.js +93 -0
- package/dist/server/password.js.map +1 -0
- package/dist/server/privacy.d.ts +33 -0
- package/dist/server/privacy.d.ts.map +1 -0
- package/dist/server/privacy.js +52 -0
- package/dist/server/privacy.js.map +1 -0
- package/dist/server/rate-limits.d.ts +22 -0
- package/dist/server/rate-limits.d.ts.map +1 -0
- package/dist/server/rate-limits.js +45 -0
- package/dist/server/rate-limits.js.map +1 -0
- package/dist/server/reauthenticate.d.ts +7 -0
- package/dist/server/reauthenticate.d.ts.map +1 -0
- package/dist/server/reauthenticate.js +16 -0
- package/dist/server/reauthenticate.js.map +1 -0
- package/dist/server/register.d.ts +23 -0
- package/dist/server/register.d.ts.map +1 -0
- package/dist/server/register.js +64 -0
- package/dist/server/register.js.map +1 -0
- package/dist/server/roles.d.ts +25 -0
- package/dist/server/roles.d.ts.map +1 -0
- package/dist/server/roles.js +56 -0
- package/dist/server/roles.js.map +1 -0
- package/dist/server/session-token.d.ts +12 -0
- package/dist/server/session-token.d.ts.map +1 -0
- package/dist/server/session-token.js +22 -0
- package/dist/server/session-token.js.map +1 -0
- package/dist/server/sessions.d.ts +24 -0
- package/dist/server/sessions.d.ts.map +1 -0
- package/dist/server/sessions.js +50 -0
- package/dist/server/sessions.js.map +1 -0
- package/dist/server/switches.d.ts +9 -0
- package/dist/server/switches.d.ts.map +1 -0
- package/dist/server/switches.js +34 -0
- package/dist/server/switches.js.map +1 -0
- package/dist/server/validation.d.ts +10 -0
- package/dist/server/validation.d.ts.map +1 -0
- package/dist/server/validation.js +32 -0
- package/dist/server/validation.js.map +1 -0
- package/dist/session-cookie.d.ts +14 -0
- package/dist/session-cookie.d.ts.map +1 -0
- package/dist/session-cookie.js +31 -0
- package/dist/session-cookie.js.map +1 -0
- package/dist/testing/account.d.ts +17 -0
- package/dist/testing/account.d.ts.map +1 -0
- package/dist/testing/account.js +31 -0
- package/dist/testing/account.js.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +4 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/ui/auth-forms.d.ts +64 -0
- package/dist/ui/auth-forms.d.ts.map +1 -0
- package/dist/ui/auth-forms.js +67 -0
- package/dist/ui/auth-forms.js.map +1 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +4 -0
- package/dist/ui/index.js.map +1 -0
- package/migrations/0001_create_users_and_sessions.sql +25 -0
- package/migrations/0002_create_user_roles.sql +10 -0
- package/migrations/0003_create_password_resets.sql +15 -0
- package/migrations/0004_index_users_created_at.sql +5 -0
- package/module.json +34 -0
- package/package.json +97 -4
- package/src/contract.ts +67 -0
- package/src/index.ts +100 -0
- package/src/mailing/index.ts +3 -0
- package/src/mailing/reset-mail.ts +73 -0
- package/src/messages/en.ts +92 -0
- package/src/messages/index.ts +15 -0
- package/src/messages/pl.ts +93 -0
- package/src/next/actions.ts +240 -0
- package/src/next/context.ts +14 -0
- package/src/next/current-user.ts +90 -0
- package/src/next/index.ts +33 -0
- package/src/next/logout-button.tsx +22 -0
- package/src/next/messages.ts +9 -0
- package/src/next/next-modules.d.ts +16 -0
- package/src/next/pages.tsx +223 -0
- package/src/next/params.ts +4 -0
- package/src/next/route.ts +17 -0
- package/src/next/search-params.ts +14 -0
- package/src/next/session-cookie.ts +79 -0
- package/src/options.ts +154 -0
- package/src/password-reset-sender.ts +33 -0
- package/src/proxy/index.ts +85 -0
- package/src/redirect-target.ts +24 -0
- package/src/roles.ts +7 -0
- package/src/safe-next-path.ts +21 -0
- package/src/schema.ts +45 -0
- package/src/scripts/index.ts +8 -0
- package/src/scripts/role-scripts.ts +98 -0
- package/src/scripts/temporary-password.ts +62 -0
- package/src/server/change-password.ts +64 -0
- package/src/server/health.ts +16 -0
- package/src/server/index.ts +46 -0
- package/src/server/login.ts +61 -0
- package/src/server/options.ts +64 -0
- package/src/server/password-reset.ts +164 -0
- package/src/server/password.ts +108 -0
- package/src/server/privacy.ts +70 -0
- package/src/server/rate-limits.ts +51 -0
- package/src/server/reauthenticate.ts +16 -0
- package/src/server/register.ts +87 -0
- package/src/server/roles.ts +72 -0
- package/src/server/session-token.ts +25 -0
- package/src/server/sessions.ts +65 -0
- package/src/server/switches.ts +31 -0
- package/src/server/validation.ts +37 -0
- package/src/session-cookie.ts +47 -0
- package/src/testing/account.ts +43 -0
- package/src/testing/index.ts +3 -0
- package/src/ui/auth-forms.tsx +383 -0
- package/src/ui/index.ts +16 -0
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
export declare const authSchema: import("drizzle-orm/pg-core").PgSchema<"auth">;
|
|
2
|
+
export declare const users: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
3
|
+
name: "users";
|
|
4
|
+
schema: "auth";
|
|
5
|
+
columns: {
|
|
6
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
7
|
+
name: "id";
|
|
8
|
+
tableName: "users";
|
|
9
|
+
dataType: "string";
|
|
10
|
+
columnType: "PgUUID";
|
|
11
|
+
data: string;
|
|
12
|
+
driverParam: string;
|
|
13
|
+
notNull: true;
|
|
14
|
+
hasDefault: true;
|
|
15
|
+
isPrimaryKey: true;
|
|
16
|
+
isAutoincrement: false;
|
|
17
|
+
hasRuntimeDefault: false;
|
|
18
|
+
enumValues: undefined;
|
|
19
|
+
baseColumn: never;
|
|
20
|
+
identity: undefined;
|
|
21
|
+
generated: undefined;
|
|
22
|
+
}, {}, {}>;
|
|
23
|
+
email: import("drizzle-orm/pg-core").PgColumn<{
|
|
24
|
+
name: "email";
|
|
25
|
+
tableName: "users";
|
|
26
|
+
dataType: "string";
|
|
27
|
+
columnType: "PgText";
|
|
28
|
+
data: string;
|
|
29
|
+
driverParam: string;
|
|
30
|
+
notNull: true;
|
|
31
|
+
hasDefault: false;
|
|
32
|
+
isPrimaryKey: false;
|
|
33
|
+
isAutoincrement: false;
|
|
34
|
+
hasRuntimeDefault: false;
|
|
35
|
+
enumValues: [string, ...string[]];
|
|
36
|
+
baseColumn: never;
|
|
37
|
+
identity: undefined;
|
|
38
|
+
generated: undefined;
|
|
39
|
+
}, {}, {}>;
|
|
40
|
+
passwordHash: import("drizzle-orm/pg-core").PgColumn<{
|
|
41
|
+
name: "password_hash";
|
|
42
|
+
tableName: "users";
|
|
43
|
+
dataType: "string";
|
|
44
|
+
columnType: "PgText";
|
|
45
|
+
data: string;
|
|
46
|
+
driverParam: string;
|
|
47
|
+
notNull: true;
|
|
48
|
+
hasDefault: false;
|
|
49
|
+
isPrimaryKey: false;
|
|
50
|
+
isAutoincrement: false;
|
|
51
|
+
hasRuntimeDefault: false;
|
|
52
|
+
enumValues: [string, ...string[]];
|
|
53
|
+
baseColumn: never;
|
|
54
|
+
identity: undefined;
|
|
55
|
+
generated: undefined;
|
|
56
|
+
}, {}, {}>;
|
|
57
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
58
|
+
name: "created_at";
|
|
59
|
+
tableName: "users";
|
|
60
|
+
dataType: "date";
|
|
61
|
+
columnType: "PgTimestamp";
|
|
62
|
+
data: Date;
|
|
63
|
+
driverParam: string;
|
|
64
|
+
notNull: true;
|
|
65
|
+
hasDefault: false;
|
|
66
|
+
isPrimaryKey: false;
|
|
67
|
+
isAutoincrement: false;
|
|
68
|
+
hasRuntimeDefault: false;
|
|
69
|
+
enumValues: undefined;
|
|
70
|
+
baseColumn: never;
|
|
71
|
+
identity: undefined;
|
|
72
|
+
generated: undefined;
|
|
73
|
+
}, {}, {}>;
|
|
74
|
+
passwordChangedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
75
|
+
name: "password_changed_at";
|
|
76
|
+
tableName: "users";
|
|
77
|
+
dataType: "date";
|
|
78
|
+
columnType: "PgTimestamp";
|
|
79
|
+
data: Date;
|
|
80
|
+
driverParam: string;
|
|
81
|
+
notNull: true;
|
|
82
|
+
hasDefault: false;
|
|
83
|
+
isPrimaryKey: false;
|
|
84
|
+
isAutoincrement: false;
|
|
85
|
+
hasRuntimeDefault: false;
|
|
86
|
+
enumValues: undefined;
|
|
87
|
+
baseColumn: never;
|
|
88
|
+
identity: undefined;
|
|
89
|
+
generated: undefined;
|
|
90
|
+
}, {}, {}>;
|
|
91
|
+
};
|
|
92
|
+
dialect: "pg";
|
|
93
|
+
}>;
|
|
94
|
+
export declare const sessions: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
95
|
+
name: "sessions";
|
|
96
|
+
schema: "auth";
|
|
97
|
+
columns: {
|
|
98
|
+
tokenHash: import("drizzle-orm/pg-core").PgColumn<{
|
|
99
|
+
name: "token_hash";
|
|
100
|
+
tableName: "sessions";
|
|
101
|
+
dataType: "string";
|
|
102
|
+
columnType: "PgText";
|
|
103
|
+
data: string;
|
|
104
|
+
driverParam: string;
|
|
105
|
+
notNull: true;
|
|
106
|
+
hasDefault: false;
|
|
107
|
+
isPrimaryKey: true;
|
|
108
|
+
isAutoincrement: false;
|
|
109
|
+
hasRuntimeDefault: false;
|
|
110
|
+
enumValues: [string, ...string[]];
|
|
111
|
+
baseColumn: never;
|
|
112
|
+
identity: undefined;
|
|
113
|
+
generated: undefined;
|
|
114
|
+
}, {}, {}>;
|
|
115
|
+
userId: import("drizzle-orm/pg-core").PgColumn<{
|
|
116
|
+
name: "user_id";
|
|
117
|
+
tableName: "sessions";
|
|
118
|
+
dataType: "string";
|
|
119
|
+
columnType: "PgUUID";
|
|
120
|
+
data: string;
|
|
121
|
+
driverParam: string;
|
|
122
|
+
notNull: true;
|
|
123
|
+
hasDefault: false;
|
|
124
|
+
isPrimaryKey: false;
|
|
125
|
+
isAutoincrement: false;
|
|
126
|
+
hasRuntimeDefault: false;
|
|
127
|
+
enumValues: undefined;
|
|
128
|
+
baseColumn: never;
|
|
129
|
+
identity: undefined;
|
|
130
|
+
generated: undefined;
|
|
131
|
+
}, {}, {}>;
|
|
132
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
133
|
+
name: "created_at";
|
|
134
|
+
tableName: "sessions";
|
|
135
|
+
dataType: "date";
|
|
136
|
+
columnType: "PgTimestamp";
|
|
137
|
+
data: Date;
|
|
138
|
+
driverParam: string;
|
|
139
|
+
notNull: true;
|
|
140
|
+
hasDefault: false;
|
|
141
|
+
isPrimaryKey: false;
|
|
142
|
+
isAutoincrement: false;
|
|
143
|
+
hasRuntimeDefault: false;
|
|
144
|
+
enumValues: undefined;
|
|
145
|
+
baseColumn: never;
|
|
146
|
+
identity: undefined;
|
|
147
|
+
generated: undefined;
|
|
148
|
+
}, {}, {}>;
|
|
149
|
+
expiresAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
150
|
+
name: "expires_at";
|
|
151
|
+
tableName: "sessions";
|
|
152
|
+
dataType: "date";
|
|
153
|
+
columnType: "PgTimestamp";
|
|
154
|
+
data: Date;
|
|
155
|
+
driverParam: string;
|
|
156
|
+
notNull: true;
|
|
157
|
+
hasDefault: false;
|
|
158
|
+
isPrimaryKey: false;
|
|
159
|
+
isAutoincrement: false;
|
|
160
|
+
hasRuntimeDefault: false;
|
|
161
|
+
enumValues: undefined;
|
|
162
|
+
baseColumn: never;
|
|
163
|
+
identity: undefined;
|
|
164
|
+
generated: undefined;
|
|
165
|
+
}, {}, {}>;
|
|
166
|
+
};
|
|
167
|
+
dialect: "pg";
|
|
168
|
+
}>;
|
|
169
|
+
export declare const userRoles: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
170
|
+
name: "user_roles";
|
|
171
|
+
schema: "auth";
|
|
172
|
+
columns: {
|
|
173
|
+
userId: import("drizzle-orm/pg-core").PgColumn<{
|
|
174
|
+
name: "user_id";
|
|
175
|
+
tableName: "user_roles";
|
|
176
|
+
dataType: "string";
|
|
177
|
+
columnType: "PgUUID";
|
|
178
|
+
data: string;
|
|
179
|
+
driverParam: string;
|
|
180
|
+
notNull: true;
|
|
181
|
+
hasDefault: false;
|
|
182
|
+
isPrimaryKey: false;
|
|
183
|
+
isAutoincrement: false;
|
|
184
|
+
hasRuntimeDefault: false;
|
|
185
|
+
enumValues: undefined;
|
|
186
|
+
baseColumn: never;
|
|
187
|
+
identity: undefined;
|
|
188
|
+
generated: undefined;
|
|
189
|
+
}, {}, {}>;
|
|
190
|
+
role: import("drizzle-orm/pg-core").PgColumn<{
|
|
191
|
+
name: "role";
|
|
192
|
+
tableName: "user_roles";
|
|
193
|
+
dataType: "string";
|
|
194
|
+
columnType: "PgText";
|
|
195
|
+
data: string;
|
|
196
|
+
driverParam: string;
|
|
197
|
+
notNull: true;
|
|
198
|
+
hasDefault: false;
|
|
199
|
+
isPrimaryKey: false;
|
|
200
|
+
isAutoincrement: false;
|
|
201
|
+
hasRuntimeDefault: false;
|
|
202
|
+
enumValues: [string, ...string[]];
|
|
203
|
+
baseColumn: never;
|
|
204
|
+
identity: undefined;
|
|
205
|
+
generated: undefined;
|
|
206
|
+
}, {}, {}>;
|
|
207
|
+
grantedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
208
|
+
name: "granted_at";
|
|
209
|
+
tableName: "user_roles";
|
|
210
|
+
dataType: "date";
|
|
211
|
+
columnType: "PgTimestamp";
|
|
212
|
+
data: Date;
|
|
213
|
+
driverParam: string;
|
|
214
|
+
notNull: true;
|
|
215
|
+
hasDefault: false;
|
|
216
|
+
isPrimaryKey: false;
|
|
217
|
+
isAutoincrement: false;
|
|
218
|
+
hasRuntimeDefault: false;
|
|
219
|
+
enumValues: undefined;
|
|
220
|
+
baseColumn: never;
|
|
221
|
+
identity: undefined;
|
|
222
|
+
generated: undefined;
|
|
223
|
+
}, {}, {}>;
|
|
224
|
+
};
|
|
225
|
+
dialect: "pg";
|
|
226
|
+
}>;
|
|
227
|
+
export declare const passwordResets: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
228
|
+
name: "password_resets";
|
|
229
|
+
schema: "auth";
|
|
230
|
+
columns: {
|
|
231
|
+
userId: import("drizzle-orm/pg-core").PgColumn<{
|
|
232
|
+
name: "user_id";
|
|
233
|
+
tableName: "password_resets";
|
|
234
|
+
dataType: "string";
|
|
235
|
+
columnType: "PgUUID";
|
|
236
|
+
data: string;
|
|
237
|
+
driverParam: string;
|
|
238
|
+
notNull: true;
|
|
239
|
+
hasDefault: false;
|
|
240
|
+
isPrimaryKey: true;
|
|
241
|
+
isAutoincrement: false;
|
|
242
|
+
hasRuntimeDefault: false;
|
|
243
|
+
enumValues: undefined;
|
|
244
|
+
baseColumn: never;
|
|
245
|
+
identity: undefined;
|
|
246
|
+
generated: undefined;
|
|
247
|
+
}, {}, {}>;
|
|
248
|
+
tokenHash: import("drizzle-orm/pg-core").PgColumn<{
|
|
249
|
+
name: "token_hash";
|
|
250
|
+
tableName: "password_resets";
|
|
251
|
+
dataType: "string";
|
|
252
|
+
columnType: "PgText";
|
|
253
|
+
data: string;
|
|
254
|
+
driverParam: string;
|
|
255
|
+
notNull: true;
|
|
256
|
+
hasDefault: false;
|
|
257
|
+
isPrimaryKey: false;
|
|
258
|
+
isAutoincrement: false;
|
|
259
|
+
hasRuntimeDefault: false;
|
|
260
|
+
enumValues: [string, ...string[]];
|
|
261
|
+
baseColumn: never;
|
|
262
|
+
identity: undefined;
|
|
263
|
+
generated: undefined;
|
|
264
|
+
}, {}, {}>;
|
|
265
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
266
|
+
name: "created_at";
|
|
267
|
+
tableName: "password_resets";
|
|
268
|
+
dataType: "date";
|
|
269
|
+
columnType: "PgTimestamp";
|
|
270
|
+
data: Date;
|
|
271
|
+
driverParam: string;
|
|
272
|
+
notNull: true;
|
|
273
|
+
hasDefault: false;
|
|
274
|
+
isPrimaryKey: false;
|
|
275
|
+
isAutoincrement: false;
|
|
276
|
+
hasRuntimeDefault: false;
|
|
277
|
+
enumValues: undefined;
|
|
278
|
+
baseColumn: never;
|
|
279
|
+
identity: undefined;
|
|
280
|
+
generated: undefined;
|
|
281
|
+
}, {}, {}>;
|
|
282
|
+
expiresAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
283
|
+
name: "expires_at";
|
|
284
|
+
tableName: "password_resets";
|
|
285
|
+
dataType: "date";
|
|
286
|
+
columnType: "PgTimestamp";
|
|
287
|
+
data: Date;
|
|
288
|
+
driverParam: string;
|
|
289
|
+
notNull: true;
|
|
290
|
+
hasDefault: false;
|
|
291
|
+
isPrimaryKey: false;
|
|
292
|
+
isAutoincrement: false;
|
|
293
|
+
hasRuntimeDefault: false;
|
|
294
|
+
enumValues: undefined;
|
|
295
|
+
baseColumn: never;
|
|
296
|
+
identity: undefined;
|
|
297
|
+
generated: undefined;
|
|
298
|
+
}, {}, {}>;
|
|
299
|
+
};
|
|
300
|
+
dialect: "pg";
|
|
301
|
+
}>;
|
|
302
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,UAAU,gDAAmB,CAAC;AAE3C,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMhB,CAAC;AAEH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOnB,CAAC;AAEH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUrB,CAAC;AAEF,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOzB,CAAC"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Drizzle view of the module's tables (migrations/0001_create_users_and_sessions.sql,
|
|
2
|
+
// 0002_create_user_roles.sql, 0003_create_password_resets.sql and the users.created_at index of
|
|
3
|
+
// 0004_index_users_created_at.sql). The migrations are the source of truth; this file only types
|
|
4
|
+
// the queries. App tables may reference `users.id`.
|
|
5
|
+
import { pgSchema, primaryKey, text, timestamp, uuid } from "drizzle-orm/pg-core";
|
|
6
|
+
export const authSchema = pgSchema("auth");
|
|
7
|
+
export const users = authSchema.table("users", {
|
|
8
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
9
|
+
email: text("email").notNull().unique("users_email_key"),
|
|
10
|
+
passwordHash: text("password_hash").notNull(),
|
|
11
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
12
|
+
passwordChangedAt: timestamp("password_changed_at", { withTimezone: true }).notNull(),
|
|
13
|
+
});
|
|
14
|
+
export const sessions = authSchema.table("sessions", {
|
|
15
|
+
tokenHash: text("token_hash").primaryKey(),
|
|
16
|
+
userId: uuid("user_id")
|
|
17
|
+
.notNull()
|
|
18
|
+
.references(() => users.id, { onDelete: "cascade" }),
|
|
19
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
20
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
21
|
+
});
|
|
22
|
+
export const userRoles = authSchema.table("user_roles", {
|
|
23
|
+
userId: uuid("user_id")
|
|
24
|
+
.notNull()
|
|
25
|
+
.references(() => users.id, { onDelete: "cascade" }),
|
|
26
|
+
role: text("role").notNull(),
|
|
27
|
+
grantedAt: timestamp("granted_at", { withTimezone: true }).notNull(),
|
|
28
|
+
}, (table) => [primaryKey({ columns: [table.userId, table.role] })]);
|
|
29
|
+
export const passwordResets = authSchema.table("password_resets", {
|
|
30
|
+
userId: uuid("user_id")
|
|
31
|
+
.primaryKey()
|
|
32
|
+
.references(() => users.id, { onDelete: "cascade" }),
|
|
33
|
+
tokenHash: text("token_hash").notNull().unique("password_resets_token_hash_key"),
|
|
34
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
35
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
36
|
+
});
|
|
37
|
+
//# s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,3 @@
|
|
|
1
|
+
export { createGrantRoleScript, createRevokeRoleScript, type RoleScriptArgs, type RoleScriptOptions } from "./role-scripts.js";
|
|
2
|
+
export { createSetTemporaryPasswordScript, type TemporaryPasswordScriptArgs, type TemporaryPasswordScriptOptions, } from "./temporary-password.js";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC/H,OAAO,EACL,gCAAgC,EAChC,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,GACpC,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// `@softure-ai/auth/scripts`: ops scripts that grant and revoke roles and set a temporary password
|
|
2
|
+
// (see the README, "Roles" and "Account recovery").
|
|
3
|
+
export { createGrantRoleScript, createRevokeRoleScript } from "./role-scripts.js";
|
|
4
|
+
export { createSetTemporaryPasswordScript, } from "./temporary-password.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,oDAAoD;AACpD,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAA+C,MAAM,mBAAmB,CAAC;AAC/H,OAAO,EACL,gCAAgC,GAGjC,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Clock, type SoftureConfig } from "@softure-ai/core";
|
|
2
|
+
import { type OpsScript } from "@softure-ai/ops/scripts";
|
|
3
|
+
export interface RoleScriptArgs {
|
|
4
|
+
readonly email: string;
|
|
5
|
+
readonly role: string;
|
|
6
|
+
}
|
|
7
|
+
export interface RoleScriptOptions {
|
|
8
|
+
/** The time stored as `granted_at`; the system clock by default. */
|
|
9
|
+
readonly clock?: Clock;
|
|
10
|
+
}
|
|
11
|
+
/** `grant-role --email=… --role=…`: stores a declared role for one account. */
|
|
12
|
+
export declare function createGrantRoleScript(config: SoftureConfig, options?: RoleScriptOptions): OpsScript<RoleScriptArgs>;
|
|
13
|
+
/** `revoke-role --email=… --role=…`: deletes a stored role of one account. */
|
|
14
|
+
export declare function createRevokeRoleScript(config: SoftureConfig, options?: RoleScriptOptions): OpsScript<RoleScriptArgs>;
|
|
15
|
+
//# sourceMappingURL=role-scripts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"role-scripts.d.ts","sourceRoot":"","sources":["../../src/scripts/role-scripts.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEnF,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAS3F,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,oEAAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACxB;AA2BD,+EAA+E;AAC/E,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,iBAAsB,GAAG,SAAS,CAAC,cAAc,CAAC,CAoBvH;AAED,8EAA8E;AAC9E,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,iBAAsB,GAAG,SAAS,CAAC,cAAc,CAAC,CAwBxH"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// The operator's way to grant and revoke roles: safe ops scripts (`@softure-ai/ops/scripts`), dry
|
|
2
|
+
// run by default, `--commit` writes. The app bundles them like its migrate step and runs them with
|
|
3
|
+
// its database URL. Reports carry the user id and roles, never the email.
|
|
4
|
+
import { ok, systemClock } from "@softure-ai/core";
|
|
5
|
+
import { defineOpsScript, refuseOpsScript } from "@softure-ai/ops/scripts";
|
|
6
|
+
import { eq } from "drizzle-orm";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { ADMIN_ROLE } from "../roles.js";
|
|
9
|
+
import { users } from "../schema.js";
|
|
10
|
+
import { getDeclaredRoles, findUserRoles, grantRole, isConfiguredAdmin, isDeclaredRole, revokeRole } from "../server/roles.js";
|
|
11
|
+
import { normalizeEmail } from "../server/validation.js";
|
|
12
|
+
const roleScriptArgs = z.strictObject({
|
|
13
|
+
email: z.string().min(1, "--email=<account email> is required"),
|
|
14
|
+
role: z.string().min(1, "--role=<role> is required"),
|
|
15
|
+
});
|
|
16
|
+
const USAGE = ["--email=<account email>", "--role=<declared role, e.g. admin>"];
|
|
17
|
+
async function findAccount(db, email) {
|
|
18
|
+
const [row] = await db.select({ id: users.id, email: users.email }).from(users).where(eq(users.email, normalizeEmail(email))).limit(1);
|
|
19
|
+
return row;
|
|
20
|
+
}
|
|
21
|
+
async function describeRoles(ctx, account) {
|
|
22
|
+
return { userId: account.id, roles: [...(await findUserRoles(ctx, account))].sort() };
|
|
23
|
+
}
|
|
24
|
+
function describeDeclared(config) {
|
|
25
|
+
return [...getDeclaredRoles(config)].join(", ");
|
|
26
|
+
}
|
|
27
|
+
/** `grant-role --email=… --role=…`: stores a declared role for one account. */
|
|
28
|
+
export function createGrantRoleScript(config, options = {}) {
|
|
29
|
+
const clock = options.clock ?? systemClock;
|
|
30
|
+
return defineOpsScript({
|
|
31
|
+
name: "grant-role",
|
|
32
|
+
description: "Grants a declared role to the account with the given email.",
|
|
33
|
+
usage: USAGE,
|
|
34
|
+
args: roleScriptArgs,
|
|
35
|
+
run: async (tx, args) => {
|
|
36
|
+
const ctx = { db: tx, clock, config };
|
|
37
|
+
if (!isDeclaredRole(config, args.role)) {
|
|
38
|
+
return refuseOpsScript(`role "${args.role}" is not declared (declared: ${describeDeclared(config)})`);
|
|
39
|
+
}
|
|
40
|
+
const account = await findAccount(tx, args.email);
|
|
41
|
+
if (account === undefined)
|
|
42
|
+
return refuseOpsScript("no account has this email");
|
|
43
|
+
const before = await describeRoles(ctx, account);
|
|
44
|
+
const granted = await grantRole(ctx, { userId: account.id, role: args.role });
|
|
45
|
+
if (!granted.ok)
|
|
46
|
+
return refuseOpsScript(`the account already has role "${args.role}"`);
|
|
47
|
+
return ok({ before, after: await describeRoles(ctx, account) });
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** `revoke-role --email=… --role=…`: deletes a stored role of one account. */
|
|
52
|
+
export function createRevokeRoleScript(config, options = {}) {
|
|
53
|
+
const clock = options.clock ?? systemClock;
|
|
54
|
+
return defineOpsScript({
|
|
55
|
+
name: "revoke-role",
|
|
56
|
+
description: "Revokes a stored role from the account with the given email.",
|
|
57
|
+
usage: USAGE,
|
|
58
|
+
args: roleScriptArgs,
|
|
59
|
+
run: async (tx, args) => {
|
|
60
|
+
const ctx = { db: tx, clock, config };
|
|
61
|
+
const account = await findAccount(tx, args.email);
|
|
62
|
+
if (account === undefined)
|
|
63
|
+
return refuseOpsScript("no account has this email");
|
|
64
|
+
const before = await describeRoles(ctx, account);
|
|
65
|
+
const revoked = await revokeRole(ctx, { userId: account.id, role: args.role });
|
|
66
|
+
if (!revoked.ok) {
|
|
67
|
+
const isFromConfig = args.role === ADMIN_ROLE && isConfiguredAdmin(config, account);
|
|
68
|
+
return refuseOpsScript(isFromConfig
|
|
69
|
+
? "admin comes from auth({ adminEmails }) in softure.config.ts; remove the email there"
|
|
70
|
+
: `the account has no stored role "${args.role}"`);
|
|
71
|
+
}
|
|
72
|
+
return ok({ before, after: await describeRoles(ctx, account) });
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=role-scripts.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,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAC/E,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;gBAChB,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBACpF,OAAO,eAAe,CACpB,YAAY;oBACV,CAAC,CAAC,qFAAqF;oBACvF,CAAC,CAAC,mCAAmC,IAAI,CAAC,IAAI,GAAG,CACpD,CAAC;YACJ,CAAC;YACD,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QAClE,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Clock, type SoftureConfig } from "@softure-ai/core";
|
|
2
|
+
import { type OpsScript } from "@softure-ai/ops/scripts";
|
|
3
|
+
export interface TemporaryPasswordScriptArgs {
|
|
4
|
+
readonly email: string;
|
|
5
|
+
}
|
|
6
|
+
export interface TemporaryPasswordScriptOptions {
|
|
7
|
+
/** The time stored as `password_changed_at`; the system clock by default. */
|
|
8
|
+
readonly clock?: Clock;
|
|
9
|
+
}
|
|
10
|
+
/** `set-temporary-password --email=…`: a new random password, every session and reset link ended. */
|
|
11
|
+
export declare function createSetTemporaryPasswordScript(config: SoftureConfig, options?: TemporaryPasswordScriptOptions): OpsScript<TemporaryPasswordScriptArgs>;
|
|
12
|
+
//# sourceMappingURL=temporary-password.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporary-password.d.ts","sourceRoot":"","sources":["../../src/scripts/temporary-password.ts"],"names":[],"mappings":"AAKA,OAAO,EAAmB,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAY3F,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,8BAA8B;IAC7C,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACxB;AASD,qGAAqG;AACrG,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,aAAa,EACrB,OAAO,GAAE,8BAAmC,GAC3C,SAAS,CAAC,2BAA2B,CAAC,CAuBxC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// The operator's account recovery: a safe ops script (`@softure-ai/ops/scripts`), dry run by
|
|
2
|
+
// default, `--commit` writes. It sets a random password, ends every session of the account and its
|
|
3
|
+
// pending reset link, and prints the password once for the operator to hand over through a channel
|
|
4
|
+
// that proves the owner (a reply to the account's own address). Reports carry the user id, never the email.
|
|
5
|
+
import { randomBytes } from "node:crypto";
|
|
6
|
+
import { ok, systemClock } from "@softure-ai/core";
|
|
7
|
+
import { defineOpsScript, refuseOpsScript } from "@softure-ai/ops/scripts";
|
|
8
|
+
import { eq } from "drizzle-orm";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { passwordResets, sessions, users } from "../schema.js";
|
|
11
|
+
import { getAuthOptions } from "../server/options.js";
|
|
12
|
+
import { hashPassword } from "../server/password.js";
|
|
13
|
+
import { revokeUserSessions } from "../server/sessions.js";
|
|
14
|
+
import { normalizeEmail } from "../server/validation.js";
|
|
15
|
+
/** Long enough to be out of guessing range in any rate limit window. */
|
|
16
|
+
const MIN_TEMPORARY_LENGTH = 20;
|
|
17
|
+
const scriptArgs = z.strictObject({ email: z.string().min(1, "--email=<account email> is required") });
|
|
18
|
+
/** A random password of `length` base64url characters. */
|
|
19
|
+
function createTemporaryPassword(length) {
|
|
20
|
+
return randomBytes(Math.ceil((length * 3) / 4)).toString("base64url").slice(0, length);
|
|
21
|
+
}
|
|
22
|
+
/** `set-temporary-password --email=…`: a new random password, every session and reset link ended. */
|
|
23
|
+
export function createSetTemporaryPasswordScript(config, options = {}) {
|
|
24
|
+
const clock = options.clock ?? systemClock;
|
|
25
|
+
return defineOpsScript({
|
|
26
|
+
name: "set-temporary-password",
|
|
27
|
+
description: "Sets a random password for the account with the given email and ends its sessions and reset link.",
|
|
28
|
+
usage: ["--email=<account email>"],
|
|
29
|
+
args: scriptArgs,
|
|
30
|
+
run: async (tx, args) => {
|
|
31
|
+
const ctx = { db: tx, clock, config };
|
|
32
|
+
const [account] = await tx.select({ id: users.id }).from(users).where(eq(users.email, normalizeEmail(args.email))).limit(1);
|
|
33
|
+
if (account === undefined)
|
|
34
|
+
return refuseOpsScript("no account has this email");
|
|
35
|
+
const before = { userId: account.id, sessions: (await tx.select().from(sessions).where(eq(sessions.userId, account.id))).length };
|
|
36
|
+
const authOptions = getAuthOptions(config);
|
|
37
|
+
const temporaryPassword = createTemporaryPassword(Math.max(authOptions.password.minLength, MIN_TEMPORARY_LENGTH));
|
|
38
|
+
const passwordHash = await hashPassword(temporaryPassword, authOptions.password.scrypt);
|
|
39
|
+
await tx.update(users).set({ passwordHash, passwordChangedAt: clock.now() }).where(eq(users.id, account.id));
|
|
40
|
+
await revokeUserSessions(ctx, account.id);
|
|
41
|
+
await tx.delete(passwordResets).where(eq(passwordResets.userId, account.id));
|
|
42
|
+
const remaining = (await tx.select().from(sessions).where(eq(sessions.userId, account.id))).length;
|
|
43
|
+
return ok({ before, after: { userId: account.id, sessions: remaining, temporaryPassword } });
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=temporary-password.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporary-password.js","sourceRoot":"","sources":["../../src/scripts/temporary-password.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,mGAAmG;AACnG,mGAAmG;AACnG,4GAA4G;AAC5G,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,EAAE,EAAE,WA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AAC,CAAC,CAAC;YAC7G,MAAM,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;YAC1C,MAAM,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;YAC7E,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YACnG,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAC;QAC/F,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Err, type Ok } from "@softure-ai/core";
|
|
2
|
+
import type { RateLimitRejection } from "@softure-ai/security";
|
|
3
|
+
import { type AuthContext } from "./sessions.js";
|
|
4
|
+
export interface ChangePasswordInput {
|
|
5
|
+
/** The token of the session making the change; it stays valid. */
|
|
6
|
+
readonly sessionToken: string;
|
|
7
|
+
readonly currentPassword: string;
|
|
8
|
+
readonly newPassword: string;
|
|
9
|
+
}
|
|
10
|
+
export type ChangePasswordErrorCode = "auth.unauthenticated" | "auth.current_password_invalid" | "auth.password_unchanged" | "auth.password_too_short" | "auth.password_too_long";
|
|
11
|
+
export type ChangePasswordResult = Ok<undefined> | Err<ChangePasswordErrorCode> | RateLimitRejection;
|
|
12
|
+
/** Changes the password of the session's user and ends their other sessions. Database errors propagate. */
|
|
13
|
+
export declare function changePassword(ctx: AuthContext, input: ChangePasswordInput): Promise<ChangePasswordResult>;
|
|
14
|
+
//# sourceMappingURL=change-password.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-password.d.ts","sourceRoot":"","sources":["../../src/server/change-password.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,KAAK,GAAG,EAAE,KAAK,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAO/D,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAIlE,MAAM,WAAW,mBAAmB;IAClC,kEAAkE;IAClE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,MAAM,uBAAuB,GAC/B,sBAAsB,GACtB,+BAA+B,GAC/B,yBAAyB,GACzB,yBAAyB,GACzB,wBAAwB,CAAC;AAE7B,MAAM,MAAM,oBAAoB,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,uBAAuB,CAAC,GAAG,kBAAkB,CAAC;AAErG,2GAA2G;AAC3G,wBAAsB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAgChH"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Password change for a signed-in user. The new password must differ from the current one. The new hash, the end of every other session of the user
|
|
2
|
+
// and of a pending reset link happen in one transaction; the session that made the change stays signed in.
|
|
3
|
+
import { err, ok } from "@softure-ai/core";
|
|
4
|
+
import { consumeRateLimit } from "@softure-ai/security/server";
|
|
5
|
+
import { and, eq, ne } from "drizzle-orm";
|
|
6
|
+
import { passwordResets, sessions, users } from "../schema.js";
|
|
7
|
+
import { getAuthOptions } from "./options.js";
|
|
8
|
+
import { hashPassword, verifyPassword } from "./password.js";
|
|
9
|
+
import { assertAuthBuckets, BUCKETS, userSubjectKey } from "./rate-limits.js";
|
|
10
|
+
import { findSessionUser } from "./sessions.js";
|
|
11
|
+
import { hashSessionToken } from "./session-token.js";
|
|
12
|
+
import { checkNewPassword } from "./validation.js";
|
|
13
|
+
/** Changes the password of the session's user and ends their other sessions. Database errors propagate. */
|
|
14
|
+
export async function changePassword(ctx, input) {
|
|
15
|
+
const options = getAuthOptions(ctx.config);
|
|
16
|
+
assertAuthBuckets(ctx.config);
|
|
17
|
+
const user = await findSessionUser(ctx, input.sessionToken);
|
|
18
|
+
if (user === null)
|
|
19
|
+
return err("auth.unauthenticated");
|
|
20
|
+
const limit = await consumeRateLimit(ctx, { bucket: BUCKETS.changePassword, key: userSubjectKey(user.id) });
|
|
21
|
+
if (!limit.ok)
|
|
22
|
+
return limit;
|
|
23
|
+
const policy = checkNewPassword(input.newPassword, options.password.minLength);
|
|
24
|
+
if (!policy.ok)
|
|
25
|
+
return policy;
|
|
26
|
+
const [stored] = await ctx.db.select({ passwordHash: users.passwordHash }).from(users).where(eq(users.id, user.id)).limit(1);
|
|
27
|
+
if (stored === undefined)
|
|
28
|
+
return err("auth.unauthenticated");
|
|
29
|
+
if (!(await verifyPassword(input.currentPassword, stored.passwordHash)))
|
|
30
|
+
return err("auth.current_password_invalid");
|
|
31
|
+
// Compared in NFC, as the hash is: another Unicode form of the same password is the same password.
|
|
32
|
+
if (input.newPassword.normalize("NFC") === input.currentPassword.normalize("NFC"))
|
|
33
|
+
return err("auth.password_unchanged");
|
|
34
|
+
const passwordHash = await hashPassword(input.newPassword, options.password.scrypt);
|
|
35
|
+
return ctx.db.transaction(async (tx) => {
|
|
36
|
+
// Conditional on the hash just verified: two parallel changes cannot both win.
|
|
37
|
+
const updated = await tx
|
|
38
|
+
.update(users)
|
|
39
|
+
.set({ passwordHash, passwordChangedAt: ctx.clock.now() })
|
|
40
|
+
.where(and(eq(users.id, user.id), eq(users.passwordHash, stored.passwordHash)))
|
|
41
|
+
.returning();
|
|
42
|
+
if (updated.length === 0)
|
|
43
|
+
return err("auth.current_password_invalid");
|
|
44
|
+
await tx.delete(sessions).where(and(eq(sessions.userId, user.id), ne(sessions.tokenHash, hashSessionToken(input.sessionToken))));
|
|
45
|
+
// A reset link requested before the change must not outlive it.
|
|
46
|
+
await tx.delete(passwordResets).where(eq(passwordResets.userId, user.id));
|
|
47
|
+
return ok();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=change-password.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-password.js","sourceRoot":"","sources":["../../src/server/change-password.ts"],"names":[],"mappings":"AAAA,oJAAoJ;AACpJ,2GAA2G;AAC3G,OAAO,EAAE,GAAG,EAAE,EAAE,EAAqB,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAoB,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAkBnD,2GAA2G;AAC3G,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAgB,EAAE,KAA0B;IAC/E,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3C,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC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