@arcote.tech/arc-auth 0.7.7 → 0.7.8
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcote.tech/arc-auth",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.8",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Reusable authentication module for Arc framework — aggregate-based auth with factory pattern",
|
|
7
7
|
"main": "./src/index.ts",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"type-check": "tsc --noEmit"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"@arcote.tech/arc": "^0.7.
|
|
13
|
+
"@arcote.tech/arc": "^0.7.8",
|
|
14
|
+
"@arcote.tech/platform": "^0.7.8",
|
|
14
15
|
"react": "^18.0.0 || ^19.0.0",
|
|
15
16
|
"typescript": "^5.0.0"
|
|
16
17
|
},
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
date,
|
|
6
6
|
mergeUnsafe,
|
|
7
7
|
string,
|
|
8
|
+
stringEnum,
|
|
8
9
|
type ArcRawShape,
|
|
9
10
|
} from "@arcote.tech/arc";
|
|
10
11
|
import type { AccountId } from "../ids/account";
|
|
@@ -87,9 +88,12 @@ export const createAccountAggregate = <
|
|
|
87
88
|
customFields,
|
|
88
89
|
),
|
|
89
90
|
async (ctx, event) => {
|
|
90
|
-
|
|
91
|
+
// Auto-verify email on registration. Framework no longer assumes
|
|
92
|
+
// an email-verification gate — apps that want one query the
|
|
93
|
+
// `isEmailVerified` field themselves (or wire a separate flow).
|
|
94
|
+
// Matches `accountRegisteredViaOAuth` behaviour for parity.
|
|
91
95
|
await ctx.set(event.payload.accountId, {
|
|
92
|
-
isEmailVerified:
|
|
96
|
+
isEmailVerified: true,
|
|
93
97
|
authMethod: "email",
|
|
94
98
|
registeredAt: event.createdAt,
|
|
95
99
|
lastSignedInAt: undefined,
|
|
@@ -150,6 +154,14 @@ export const createAccountAggregate = <
|
|
|
150
154
|
customFields,
|
|
151
155
|
),
|
|
152
156
|
)
|
|
157
|
+
.withResult(
|
|
158
|
+
{ accountId, token: string() },
|
|
159
|
+
{
|
|
160
|
+
error: stringEnum("EMAIL_ALREADY_TAKEN"),
|
|
161
|
+
accountId,
|
|
162
|
+
token: string(),
|
|
163
|
+
},
|
|
164
|
+
)
|
|
153
165
|
.handle(
|
|
154
166
|
ONLY_SERVER &&
|
|
155
167
|
(async (ctx, params) => {
|
|
@@ -157,7 +169,11 @@ export const createAccountAggregate = <
|
|
|
157
169
|
email: params.email,
|
|
158
170
|
});
|
|
159
171
|
if (existing) {
|
|
160
|
-
return {
|
|
172
|
+
return {
|
|
173
|
+
error: "EMAIL_ALREADY_TAKEN" as const,
|
|
174
|
+
accountId: existing._id,
|
|
175
|
+
token: token.generateJWT(buildTokenParams(existing)),
|
|
176
|
+
};
|
|
161
177
|
}
|
|
162
178
|
|
|
163
179
|
const id = accountId.generate();
|
|
@@ -169,7 +185,12 @@ export const createAccountAggregate = <
|
|
|
169
185
|
passwordHash: pwHash,
|
|
170
186
|
});
|
|
171
187
|
|
|
172
|
-
return {
|
|
188
|
+
return {
|
|
189
|
+
accountId: id,
|
|
190
|
+
token: token.generateJWT(
|
|
191
|
+
buildTokenParams({ _id: id, ...params }),
|
|
192
|
+
),
|
|
193
|
+
};
|
|
173
194
|
}),
|
|
174
195
|
),
|
|
175
196
|
)
|
|
@@ -187,7 +208,7 @@ export const createAccountAggregate = <
|
|
|
187
208
|
email: params.email,
|
|
188
209
|
});
|
|
189
210
|
|
|
190
|
-
if (!account) {
|
|
211
|
+
if (!account || !account.passwordHash) {
|
|
191
212
|
return { error: "INVALID_EMAIL_OR_PASSWORD" as const };
|
|
192
213
|
}
|
|
193
214
|
|
|
@@ -199,13 +220,6 @@ export const createAccountAggregate = <
|
|
|
199
220
|
return { error: "INVALID_EMAIL_OR_PASSWORD" as const };
|
|
200
221
|
}
|
|
201
222
|
|
|
202
|
-
if (!account.isEmailVerified) {
|
|
203
|
-
return {
|
|
204
|
-
error: "EMAIL_NOT_VERIFIED" as const,
|
|
205
|
-
email: params.email,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
|
|
209
223
|
const jwtToken = token.generateJWT(buildTokenParams(account));
|
|
210
224
|
|
|
211
225
|
await ctx.signedIn.emit({
|
|
@@ -251,11 +265,10 @@ export const createAccountAggregate = <
|
|
|
251
265
|
accountId: id,
|
|
252
266
|
});
|
|
253
267
|
|
|
254
|
-
const newAccount = await ctx.$query.findOne({ _id: id });
|
|
255
268
|
return {
|
|
256
269
|
accountId: id,
|
|
257
270
|
token: token.generateJWT(
|
|
258
|
-
buildTokenParams(
|
|
271
|
+
buildTokenParams({ _id: id, ...params }),
|
|
259
272
|
),
|
|
260
273
|
};
|
|
261
274
|
}),
|
|
@@ -292,12 +305,10 @@ export const createAccountAggregate = <
|
|
|
292
305
|
),
|
|
293
306
|
)
|
|
294
307
|
|
|
295
|
-
.protectBy(token, (params) => ({ _id: params.accountId }))
|
|
296
|
-
.clientQuery("getAll", (fn) =>
|
|
297
|
-
fn.handle(async (ctx) => ctx.$query.find({})),
|
|
298
|
-
)
|
|
299
308
|
.clientQuery("getMe", (fn) =>
|
|
300
|
-
fn
|
|
309
|
+
fn
|
|
310
|
+
.protectedBy(token, (params) => ({ _id: params.accountId }))
|
|
311
|
+
.handle(async (ctx) => ctx.$query.findOne({})),
|
|
301
312
|
)
|
|
302
313
|
);
|
|
303
314
|
};
|
package/src/react/auth-page.tsx
CHANGED
|
@@ -72,8 +72,6 @@ export function AuthPage({
|
|
|
72
72
|
if (result && "error" in result) {
|
|
73
73
|
if (result.error === "INVALID_EMAIL_OR_PASSWORD") {
|
|
74
74
|
setError("Nieprawidłowy email lub hasło.");
|
|
75
|
-
} else if (result.error === "EMAIL_NOT_VERIFIED") {
|
|
76
|
-
setError("Email nie został zweryfikowany.");
|
|
77
75
|
} else {
|
|
78
76
|
setError("Wystąpił błąd podczas logowania.");
|
|
79
77
|
}
|
|
@@ -49,8 +49,6 @@ export function SignInPage({ signIn, navigate, render }: SignInPageProps) {
|
|
|
49
49
|
if (result && "error" in result) {
|
|
50
50
|
if (result.error === "INVALID_EMAIL_OR_PASSWORD") {
|
|
51
51
|
setError("Nieprawidłowy email lub hasło.");
|
|
52
|
-
} else if (result.error === "EMAIL_NOT_VERIFIED") {
|
|
53
|
-
setError("Email nie został zweryfikowany.");
|
|
54
52
|
} else {
|
|
55
53
|
setError("Wystąpił błąd podczas logowania.");
|
|
56
54
|
}
|