@gasboost/auth 0.6.0 → 0.7.0
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
CHANGED
|
@@ -339,7 +339,8 @@ Session 発行
|
|
|
339
339
|
|
|
340
340
|
`@gasboost/auth` は、認証成功後に外部処理を実行するための lifecycle hook を提供します。
|
|
341
341
|
|
|
342
|
-
現在は `afterSignIn` を利用できます。
|
|
342
|
+
現在は `afterSignIn` を利用できます。Sign In と、Session を自動発行する Sign Up の
|
|
343
|
+
email / Apps Script 両経路で、Session 保存後に同じ Hook を1回 await します。
|
|
343
344
|
|
|
344
345
|
```ts
|
|
345
346
|
import { AppsScriptAuth, type EmailPasswordAuthOptions } from "@gasboost/auth";
|
|
@@ -384,7 +385,7 @@ hooks: {
|
|
|
384
385
|
},
|
|
385
386
|
```
|
|
386
387
|
|
|
387
|
-
hook の戻り値は Sign In result の `hooks` から取得できます。
|
|
388
|
+
hook の戻り値は Sign In / Sign Up result の `hooks` から取得できます。
|
|
388
389
|
|
|
389
390
|
```ts
|
|
390
391
|
const result = await auth.signIn.email({
|
|
@@ -409,7 +410,7 @@ const auth = new AppsScriptAuth<EmailPasswordAuthOptions, HookResult>({
|
|
|
409
410
|
});
|
|
410
411
|
```
|
|
411
412
|
|
|
412
|
-
hook を設定しない場合、従来どおり Sign In result は `user` と `session` のみを返します。
|
|
413
|
+
hook を設定しない場合、従来どおり Sign In / Sign Up result は `user` と `session` のみを返します。
|
|
413
414
|
|
|
414
415
|
```ts
|
|
415
416
|
const auth = new AppsScriptAuth({
|
|
@@ -448,7 +449,7 @@ hooks: {
|
|
|
448
449
|
|
|
449
450
|
### Hook Failure
|
|
450
451
|
|
|
451
|
-
`afterSignIn` は Sign In 処理の一部として扱われます。
|
|
452
|
+
`afterSignIn` は Sign In / Sign Up 処理の一部として扱われます。
|
|
452
453
|
|
|
453
454
|
処理順序は以下です。
|
|
454
455
|
|
|
@@ -466,9 +467,11 @@ afterSignIn
|
|
|
466
467
|
Sign In result
|
|
467
468
|
```
|
|
468
469
|
|
|
469
|
-
`afterSignIn` で例外が発生した場合、Sign In 全体が失敗します。
|
|
470
|
+
`afterSignIn` で例外が発生した場合、Sign In / Sign Up 全体が失敗します。
|
|
470
471
|
|
|
471
472
|
その際、すでに保存された Session は SessionStorage から削除されます。
|
|
473
|
+
削除が失敗しても元の Hook エラーを返します。Sign Up で作成済みの User / Account は削除しません。
|
|
474
|
+
登録は完了しているため、再認証には Sign In を使い、Sign Up を自動再試行しないでください。
|
|
472
475
|
|
|
473
476
|
```text
|
|
474
477
|
afterSignIn error
|
package/dist/AppsScriptAuth.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ type AppsScriptAuthPasswordApi<TEmailPassword> = TEmailPassword extends {
|
|
|
32
32
|
} ? AppsScriptAuthPassword : undefined;
|
|
33
33
|
export declare class AppsScriptAuth<TEmailPassword extends EmailPasswordAuthOptions | undefined = undefined, THookResult = undefined> {
|
|
34
34
|
readonly signIn: AppsScriptAuthSignIn<THookResult>;
|
|
35
|
-
readonly signUp: AppsScriptAuthSignUp
|
|
35
|
+
readonly signUp: AppsScriptAuthSignUp<THookResult>;
|
|
36
36
|
readonly session: AppsScriptAuthSession;
|
|
37
37
|
readonly signOut: AppsScriptAuthSignOut;
|
|
38
38
|
readonly password: AppsScriptAuthPasswordApi<TEmailPassword>;
|
package/dist/AppsScriptAuth.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import type { AppsScriptAuthenticationConfig } from "../authentication/AppsScriptAuthentication";
|
|
2
2
|
import type { EmailPasswordAuthConfig } from "../authentication/EmailPasswordAuthentication";
|
|
3
|
+
import type { AfterSignInHook } from "../hooks/AuthHooks";
|
|
3
4
|
import { type AppsScriptRegistrationInput } from "../registration/AppsScriptRegistration";
|
|
4
5
|
import { type EmailPasswordRegistrationInput } from "../registration/EmailPasswordRegistration";
|
|
5
6
|
import type { AppsScriptAuthRepository } from "../storage/AppsScriptAuthRepository";
|
|
6
7
|
import type { AppsScriptSessionStorage } from "../storage/AppsScriptSessionStorage";
|
|
7
8
|
import { SignUp } from "./SignUp";
|
|
8
|
-
export declare class AppsScriptAuthSignUp {
|
|
9
|
-
email: SignUp<EmailPasswordRegistrationInput>["execute"];
|
|
10
|
-
appsScript: SignUp<AppsScriptRegistrationInput>["execute"];
|
|
11
|
-
constructor({ sessionStorage, expiresIn, repository, emailPassword, appsScript, utilities, session, }: {
|
|
9
|
+
export declare class AppsScriptAuthSignUp<THookResult = undefined> {
|
|
10
|
+
email: SignUp<EmailPasswordRegistrationInput, THookResult>["execute"];
|
|
11
|
+
appsScript: SignUp<AppsScriptRegistrationInput, THookResult>["execute"];
|
|
12
|
+
constructor({ sessionStorage, expiresIn, afterSignIn, repository, emailPassword, appsScript, utilities, session, }: {
|
|
12
13
|
sessionStorage: AppsScriptSessionStorage;
|
|
13
14
|
expiresIn: number;
|
|
15
|
+
afterSignIn?: AfterSignInHook<THookResult>;
|
|
14
16
|
repository: AppsScriptAuthRepository;
|
|
15
17
|
emailPassword?: EmailPasswordAuthConfig;
|
|
16
18
|
appsScript?: AppsScriptAuthenticationConfig;
|
|
@@ -7,7 +7,7 @@ const SignUp_1 = require("./SignUp");
|
|
|
7
7
|
class AppsScriptAuthSignUp {
|
|
8
8
|
email;
|
|
9
9
|
appsScript;
|
|
10
|
-
constructor({ sessionStorage, expiresIn, repository, emailPassword, appsScript, utilities, session, }) {
|
|
10
|
+
constructor({ sessionStorage, expiresIn, afterSignIn, repository, emailPassword, appsScript, utilities, session, }) {
|
|
11
11
|
this.email = async (input) => {
|
|
12
12
|
if (!emailPassword) {
|
|
13
13
|
throw new Error("Email and password authentication is disabled");
|
|
@@ -15,6 +15,7 @@ class AppsScriptAuthSignUp {
|
|
|
15
15
|
emailPassword.ensureSignUpEnabled();
|
|
16
16
|
const emailSignUp = new SignUp_1.SignUp({
|
|
17
17
|
sessionStorage,
|
|
18
|
+
afterSignIn,
|
|
18
19
|
expiresIn,
|
|
19
20
|
registration: new EmailPasswordRegistration_1.EmailPasswordRegistration(repository, utilities, emailPassword),
|
|
20
21
|
utilities,
|
|
@@ -28,6 +29,7 @@ class AppsScriptAuthSignUp {
|
|
|
28
29
|
appsScript.ensureSignUpEnabled();
|
|
29
30
|
const appsScriptSignUp = new SignUp_1.SignUp({
|
|
30
31
|
sessionStorage,
|
|
32
|
+
afterSignIn,
|
|
31
33
|
expiresIn,
|
|
32
34
|
registration: new AppsScriptRegistration_1.AppsScriptRegistration(utilities, session, repository),
|
|
33
35
|
utilities,
|
package/dist/api/SignUp.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { User } from "../domain/User";
|
|
1
|
+
import type { AfterSignInHook } from "../hooks/AuthHooks";
|
|
3
2
|
import type { Registration } from "../registration/Registration";
|
|
4
3
|
import type { AppsScriptSessionStorage } from "../storage/AppsScriptSessionStorage";
|
|
5
|
-
|
|
4
|
+
import type { SignInResult } from "./SignIn";
|
|
5
|
+
export type SignUpResult<THookResult = undefined> = SignInResult<THookResult>;
|
|
6
|
+
export declare class SignUp<T, THookResult = undefined> {
|
|
7
|
+
private readonly afterSignIn;
|
|
6
8
|
private readonly sessionStorage;
|
|
7
9
|
private readonly registration;
|
|
8
10
|
private readonly utilities;
|
|
9
11
|
private readonly expiresIn;
|
|
10
|
-
constructor({ sessionStorage, registration, utilities, expiresIn, }: {
|
|
12
|
+
constructor({ sessionStorage, registration, utilities, expiresIn, afterSignIn, }: {
|
|
11
13
|
sessionStorage: AppsScriptSessionStorage;
|
|
12
14
|
registration: Registration<T>;
|
|
13
15
|
utilities: GoogleAppsScript.Utilities.Utilities;
|
|
14
16
|
expiresIn: number;
|
|
17
|
+
afterSignIn?: AfterSignInHook<THookResult>;
|
|
15
18
|
});
|
|
16
|
-
execute(input: T): Promise<
|
|
17
|
-
user: User;
|
|
18
|
-
session: Session;
|
|
19
|
-
}>;
|
|
19
|
+
execute(input: T): Promise<SignUpResult<THookResult>>;
|
|
20
20
|
}
|
package/dist/api/SignUp.js
CHANGED
|
@@ -3,15 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SignUp = void 0;
|
|
4
4
|
const Session_1 = require("../domain/Session");
|
|
5
5
|
class SignUp {
|
|
6
|
+
afterSignIn;
|
|
6
7
|
sessionStorage;
|
|
7
8
|
registration;
|
|
8
9
|
utilities;
|
|
9
10
|
expiresIn;
|
|
10
|
-
constructor({ sessionStorage, registration, utilities, expiresIn, }) {
|
|
11
|
+
constructor({ sessionStorage, registration, utilities, expiresIn, afterSignIn, }) {
|
|
11
12
|
this.sessionStorage = sessionStorage;
|
|
12
13
|
this.registration = registration;
|
|
13
14
|
this.utilities = utilities;
|
|
14
15
|
this.expiresIn = expiresIn;
|
|
16
|
+
this.afterSignIn = afterSignIn;
|
|
15
17
|
}
|
|
16
18
|
async execute(input) {
|
|
17
19
|
const user = await this.registration.register(input);
|
|
@@ -23,7 +25,22 @@ class SignUp {
|
|
|
23
25
|
expiresAt: new Date(now.getTime() + this.expiresIn),
|
|
24
26
|
});
|
|
25
27
|
await this.sessionStorage.save(session);
|
|
26
|
-
|
|
28
|
+
if (!this.afterSignIn) {
|
|
29
|
+
return { user, session };
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const hooks = await this.afterSignIn({ user, session });
|
|
33
|
+
return { user, session, hooks };
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
try {
|
|
37
|
+
await this.sessionStorage.delete(session.id);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Preserve the original hook error. Registration remains intact.
|
|
41
|
+
}
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
27
44
|
}
|
|
28
45
|
}
|
|
29
46
|
exports.SignUp = SignUp;
|
package/package.json
CHANGED