@shivaedev/identity 0.13.0 → 0.14.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/CHANGELOG.md +11 -0
- package/README.md +16 -15
- package/dist/server/better-auth/testing.d.ts +27 -4
- package/dist/server/better-auth/testing.d.ts.map +1 -1
- package/dist/server/better-auth/testing.js +11 -7
- package/dist/server/better-auth/testing.js.map +1 -1
- package/dist/sessions.d.ts +4 -4
- package/dist/sessions.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/server/better-auth/testing.ts +12 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.14.0 - 2026-10-31
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Signed-in test sessions expire after Better Auth's configured session lifetime on Effect's Clock, so stories set decades ahead stay signed in until that lifetime ends.
|
|
8
|
+
|
|
9
|
+
### Breaking
|
|
10
|
+
|
|
11
|
+
- `signedInUser(auth, fields)` returns an Effect instead of a Promise so session minting reads the caller's Clock. In Effect code, replace `yield* Effect.promise(() => signedInUser(auth, fields))` with `yield* signedInUser(auth, fields)`. At a Promise boundary, run it with `Effect.runPromise` or the application's Effect runtime.
|
|
12
|
+
- Stories that also call Better Auth's auth endpoints must start TestClock at the present or a future date, because those endpoints still use the wall clock.
|
|
13
|
+
|
|
3
14
|
## 0.13.0 - 2026-10-31
|
|
4
15
|
|
|
5
16
|
### Added
|
package/README.md
CHANGED
|
@@ -581,26 +581,29 @@ Use `testUtils()` from `better-auth/plugins` in a test-only Better Auth instance
|
|
|
581
581
|
|
|
582
582
|
Use `authTestDatabase` from `@shivaedev/identity/server/better-auth/testDatabase.ts` when a story needs observations or faults in the default Better Auth PostgreSQL schema. It returns Effect readouts `users` (IDs and emails) and `sessions` (IDs, user IDs and emails), plus `migrate(options, roleOptions?)`, `roleColumn` (PostgreSQL type, nullability and default), `userRoles` (emails and roles), and the test-only faults `expireSessions(userId?)`, `omitImageColumn` and `omitRole(userId)`. The last fault makes a role nullable and clears that user's role to model a partial migration. Pass a user id to expire only that user's sessions, or call `expireSessions()` to expire every session. It never returns tokens, password hashes or provider credentials. These fixtures assume the default table and column mappings and read `SqlClient` from the Effect environment; use only an isolated test database. Application stories keep their auth SQL in this provider-owned boundary.
|
|
583
583
|
|
|
584
|
-
`authTestDatabase` also exposes `sessionsFor(userId)`, returning that user’s stored sessions as `{ id, expiresAt, expired }`. `expiresAt` is a native Effect UTC value; `expired` compares it with Effect’s current clock. Expired sessions remain visible until removed. Revocation deletes a session, so its id disappears from this readout; it keeps no revocation history. For expiry stories, advance `TestClock` to the minted session’s expiry instead of rewriting storage timestamps. Identity’s Better Auth session provider, session administration list and expired-session sweep use Effect’s clock. Better Auth’s own auth endpoints,
|
|
584
|
+
`authTestDatabase` also exposes `sessionsFor(userId)`, returning that user’s stored sessions as `{ id, expiresAt, expired }`. `expiresAt` is a native Effect UTC value; `expired` compares it with Effect’s current clock. Expired sessions remain visible until removed. Revocation deletes a session, so its id disappears from this readout; it keeps no revocation history. For expiry stories, advance `TestClock` to the minted session’s expiry instead of rewriting storage timestamps. Identity’s Better Auth session provider, session administration list and expired-session sweep use Effect’s clock. Sessions minted by `signedInUser` take their expiry from Effect’s Clock and Better Auth’s configured session lifetime. Better Auth’s own auth endpoints, direct `testUtils` calls and session refresh still use the provider’s clock.
|
|
585
585
|
|
|
586
586
|
```ts
|
|
587
587
|
import { betterAuth } from "better-auth";
|
|
588
588
|
import { testUtils } from "better-auth/plugins";
|
|
589
|
+
import { Effect } from "effect";
|
|
589
590
|
import { signedInUser } from "@shivaedev/identity/server/better-auth/testing.ts";
|
|
590
591
|
|
|
591
592
|
const testAuth = betterAuth({
|
|
592
593
|
...options,
|
|
593
594
|
plugins: [...(options.plugins ?? []), testUtils()],
|
|
594
595
|
});
|
|
595
|
-
const { user, headers, cookies } = await
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
596
|
+
const { user, headers, cookies } = await Effect.runPromise(
|
|
597
|
+
signedInUser(testAuth, {
|
|
598
|
+
email: "member@example.test",
|
|
599
|
+
name: "Member",
|
|
600
|
+
providerAccounts: [{ providerId: "github", accountId: "123" }],
|
|
601
|
+
role: "user,admin",
|
|
602
|
+
}),
|
|
603
|
+
);
|
|
601
604
|
```
|
|
602
605
|
|
|
603
|
-
`options` is the application's auth configuration. `signedInUser` saves the supplied user fields, creates each optional `providerAccounts` entry for that user through Better Auth's internal adapter, and mints one session through Better Auth's `testUtils`, without OAuth or password hashing. The accounts carry no tokens or password. Omitting `providerAccounts` creates only the user and session. It returns Better Auth's login result: the user, session, signed request headers, browser cookies and token. To mint users with roles, use the auth instance returned by `betterAuthMount(options, { defaultRole: "member", roles: Access })`. Send `headers` to the real host, or pass `cookies` to test-story's `seedCookies` in a DOM story after setting its host location with `domFetch`. Keep a real sign-in story for each sign-in flow; feature stories start from the minted precondition.
|
|
606
|
+
`options` is the application's auth configuration. `signedInUser` saves the supplied user fields, creates each optional `providerAccounts` entry for that user through Better Auth's internal adapter, and mints one session through Better Auth's `testUtils`, without OAuth or password hashing. The accounts carry no tokens or password. Omitting `providerAccounts` creates only the user and session. It returns an Effect containing Better Auth's login result: the user, session, signed request headers, browser cookies and token. In a story, call `yield* signedInUser(auth, fields)` so minting uses that story's TestClock. If the story also calls Better Auth's auth endpoints, start its TestClock at the present or a future date because those endpoints still check the provider's wall clock. To mint users with roles, use the auth instance returned by `betterAuthMount(options, { defaultRole: "member", roles: Access })`. Send `headers` to the real host, or pass `cookies` to test-story's `seedCookies` in a DOM story after setting its host location with `domFetch`. Keep a real sign-in story for each sign-in flow; feature stories start from the minted precondition.
|
|
604
607
|
|
|
605
608
|
`passwordUser(auth, { email, password, ...fields })` from the same testing module saves a user and a credential account using Better Auth's configured password hasher, and returns an Effect containing the user without minting a session. Use it for the one story that signs in through `/api/auth/sign-in/email`; keep feature stories on `signedInUser` so they avoid password hashing.
|
|
606
609
|
|
|
@@ -613,13 +616,11 @@ import { seedCookies } from "@shivaedev/test-story/server/seedCookies.ts";
|
|
|
613
616
|
import { signedInUser, storedProviderAccounts } from "@shivaedev/identity/server/better-auth/testing.ts";
|
|
614
617
|
|
|
615
618
|
const member = app.trait("account", "a member starts signed in with GitHub", function* ({ auth }) {
|
|
616
|
-
const { cookies } = yield*
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
}),
|
|
622
|
-
);
|
|
619
|
+
const { cookies } = yield* signedInUser(auth, {
|
|
620
|
+
email: "member@example.test",
|
|
621
|
+
name: "Member",
|
|
622
|
+
providerAccounts: [{ providerId: "github", accountId: "123" }],
|
|
623
|
+
});
|
|
623
624
|
yield* seedCookies(cookies);
|
|
624
625
|
});
|
|
625
626
|
|
|
@@ -3,14 +3,37 @@ import type { testUtils } from "better-auth/plugins";
|
|
|
3
3
|
import { Effect } from "effect";
|
|
4
4
|
type TestContext = ReturnType<ReturnType<typeof testUtils>["init"]>["context"];
|
|
5
5
|
type AccountContext = Pick<AuthContext, "internalAdapter">;
|
|
6
|
-
export declare
|
|
7
|
-
readonly $context: Promise<TestContext & AccountContext
|
|
8
|
-
},
|
|
6
|
+
export declare const signedInUser: (auth: {
|
|
7
|
+
readonly $context: Promise<TestContext & AccountContext & Pick<AuthContext, "sessionConfig">>;
|
|
8
|
+
}, args_1: Partial<{
|
|
9
|
+
id: string;
|
|
10
|
+
createdAt: Date;
|
|
11
|
+
updatedAt: Date;
|
|
12
|
+
email: string;
|
|
13
|
+
emailVerified: boolean;
|
|
14
|
+
name: string;
|
|
15
|
+
image?: string | null | undefined;
|
|
16
|
+
}> & Record<string, unknown> & {
|
|
9
17
|
readonly providerAccounts?: readonly {
|
|
10
18
|
readonly providerId: string;
|
|
11
19
|
readonly accountId: string;
|
|
12
20
|
}[];
|
|
13
|
-
})
|
|
21
|
+
}) => Effect.Effect<{
|
|
22
|
+
user: import("better-auth").User;
|
|
23
|
+
headers: Headers;
|
|
24
|
+
cookies: import("better-auth/plugins").TestCookie[];
|
|
25
|
+
token: string;
|
|
26
|
+
session: {
|
|
27
|
+
id: string;
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
updatedAt: Date;
|
|
30
|
+
userId: string;
|
|
31
|
+
token: string;
|
|
32
|
+
ipAddress?: string | null | undefined;
|
|
33
|
+
userAgent?: string | null | undefined;
|
|
34
|
+
expiresAt: Date;
|
|
35
|
+
};
|
|
36
|
+
}, never, never>;
|
|
14
37
|
export declare function storedProviderAccounts(auth: {
|
|
15
38
|
readonly $context: Promise<AccountContext>;
|
|
16
39
|
}, userId: string): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAS,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEvC,KAAK,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAC/E,KAAK,cAAc,GAAG,IAAI,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;AAE3D,eAAO,MAAM,YAAY;uBACG,OAAO,CAAC,WAAW,GAAG,cAAc,GAAG,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;;;;;;;;;;gCAKxE,SAAS;QAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE;;;;;;;;;;;;;;;;gBAalG,CAAC;AAEH,wBAAsB,sBAAsB,CAAC,IAAI,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;CAAE,EAAE,MAAM,EAAE,MAAM;;;;;;;KAWhH;AAED,eAAO,MAAM,YAAY;uBACG,OAAO,CAAC,WAAW,GAAG,cAAc,GAAG;QAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;;;;;;;;;;oBACjC,MAAM;uBAAqB,MAAM;;;;;;;;;gBAO9H,CAAC"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
export
|
|
3
|
-
const { test, internalAdapter } =
|
|
4
|
-
const user =
|
|
1
|
+
import { Clock, Effect } from "effect";
|
|
2
|
+
export const signedInUser = Effect.fnUntraced(function* (auth, { providerAccounts = [], ...fields }) {
|
|
3
|
+
const { test, internalAdapter, sessionConfig } = yield* Effect.promise(() => auth.$context);
|
|
4
|
+
const user = yield* Effect.promise(() => test.saveUser(test.createUser(fields)));
|
|
5
5
|
for (const { providerId, accountId } of providerAccounts) {
|
|
6
|
-
|
|
6
|
+
yield* Effect.promise(() => internalAdapter.createAccount({ accountId, providerId, userId: user.id }));
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
}
|
|
8
|
+
const now = yield* Clock.currentTimeMillis;
|
|
9
|
+
const login = yield* Effect.promise(() => test.login({ userId: user.id }));
|
|
10
|
+
const expiresAt = new Date(now + sessionConfig.expiresIn * 1000);
|
|
11
|
+
yield* Effect.promise(() => internalAdapter.updateSession(login.token, { expiresAt }));
|
|
12
|
+
return { ...login, session: { ...login.session, expiresAt } };
|
|
13
|
+
});
|
|
10
14
|
export async function storedProviderAccounts(auth, userId) {
|
|
11
15
|
const { internalAdapter } = await auth.$context;
|
|
12
16
|
const accounts = await internalAdapter.findAccounts(userId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../../../src/server/better-auth/testing.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../../../src/server/better-auth/testing.ts"],"names":[],"mappings":"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"}
|
package/dist/sessions.d.ts
CHANGED
|
@@ -100,9 +100,7 @@ export declare const Sessions: import("@shivaedev/contract/contract.ts").Contrac
|
|
|
100
100
|
readonly queryIndexes: Schema.optional<Schema.$Array<Schema.Number>>;
|
|
101
101
|
}>, Schema.Struct<{
|
|
102
102
|
readonly _tag: Schema.Literal<"Resync">;
|
|
103
|
-
}>]>, ...never[]]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired, ...Schema.Union<readonly (typeof Forbidden | typeof AuthUnavailable)[]>[]]>>, Schema.Never, typeof SessionsPermission, never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.
|
|
104
|
-
id: Schema.String;
|
|
105
|
-
}>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable)[]>, typeof SessionsPermission, never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.list", Schema.Struct<{
|
|
103
|
+
}>]>, ...never[]]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired, ...Schema.Union<readonly (typeof Forbidden | typeof AuthUnavailable)[]>[]]>>, Schema.Never, typeof SessionsPermission, never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.list", Schema.Struct<{
|
|
106
104
|
readonly cursor: Schema.optionalKey<Schema.Struct<{
|
|
107
105
|
readonly id: Schema.String;
|
|
108
106
|
readonly lastActivityAt: Schema.DateTimeUtcFromString;
|
|
@@ -124,5 +122,7 @@ export declare const Sessions: import("@shivaedev/contract/contract.ts").Contrac
|
|
|
124
122
|
readonly name: Schema.String;
|
|
125
123
|
}>;
|
|
126
124
|
}>>;
|
|
127
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof Forbidden | typeof AuthUnavailable)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof SessionsPermission, never
|
|
125
|
+
}>, Schema.Union<readonly [Schema.Union<readonly (typeof Forbidden | typeof AuthUnavailable)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof SessionsPermission, never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.revoke", Schema.Struct<{
|
|
126
|
+
id: Schema.String;
|
|
127
|
+
}>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable)[]>, typeof SessionsPermission, never>, readonly [], undefined>;
|
|
128
128
|
//# sourceMappingURL=sessions.d.ts.map
|
package/dist/sessions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIxC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAI5D,eAAO,MAAM,eAAe;;;;;;;;;;EAM1B,CAAC;AAEH,eAAO,MAAM,aAAa;;;EAAqF,CAAC;AAChH,eAAO,MAAM,gBAAgB;;;;;;EAG3B,CAAC;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;EAA2G,CAAC;AAEpI,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIxC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAI5D,eAAO,MAAM,eAAe;;;;;;;;;;EAM1B,CAAC;AAEH,eAAO,MAAM,aAAa;;;EAAqF,CAAC;AAChH,eAAO,MAAM,gBAAgB;;;;;;EAG3B,CAAC;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;EAA2G,CAAC;AAEpI,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mKAiBY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/identity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Request identity, sessions, transport trust and permission enforcement for Effect RPC servers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -49,17 +49,17 @@
|
|
|
49
49
|
"@shivaedev/changes": "0.6.0",
|
|
50
50
|
"@shivaedev/contract": "0.30.0",
|
|
51
51
|
"@shivaedev/errors": "0.4.0",
|
|
52
|
-
"@shivaedev/sql": "0.
|
|
52
|
+
"@shivaedev/sql": "0.29.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@effect/platform-node": "4.0.6",
|
|
56
56
|
"@effect/sql-pg": "4.0.6",
|
|
57
|
-
"@shivaedev/admin": "0.16.
|
|
57
|
+
"@shivaedev/admin": "0.16.1",
|
|
58
58
|
"@shivaedev/quality": "0.52.0",
|
|
59
|
-
"@shivaedev/server": "0.
|
|
59
|
+
"@shivaedev/server": "0.15.0",
|
|
60
60
|
"@shivaedev/test": "0.12.0",
|
|
61
|
-
"@shivaedev/test-sql": "0.15.
|
|
62
|
-
"@shivaedev/test-story": "0.31.
|
|
61
|
+
"@shivaedev/test-sql": "0.15.2",
|
|
62
|
+
"@shivaedev/test-story": "0.31.2",
|
|
63
63
|
"@types/node": "24.19.2",
|
|
64
64
|
"better-auth": "1.7.12",
|
|
65
65
|
"effect": "4.0.6",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { AuthContext } from "better-auth";
|
|
2
2
|
import type { testUtils } from "better-auth/plugins";
|
|
3
|
-
import { Effect } from "effect";
|
|
3
|
+
import { Clock, Effect } from "effect";
|
|
4
4
|
|
|
5
5
|
type TestContext = ReturnType<ReturnType<typeof testUtils>["init"]>["context"];
|
|
6
6
|
type AccountContext = Pick<AuthContext, "internalAdapter">;
|
|
7
7
|
|
|
8
|
-
export
|
|
9
|
-
auth: { readonly $context: Promise<TestContext & AccountContext
|
|
8
|
+
export const signedInUser = Effect.fnUntraced(function* (
|
|
9
|
+
auth: { readonly $context: Promise<TestContext & AccountContext & Pick<AuthContext, "sessionConfig">> },
|
|
10
10
|
{
|
|
11
11
|
providerAccounts = [],
|
|
12
12
|
...fields
|
|
@@ -14,13 +14,17 @@ export async function signedInUser(
|
|
|
14
14
|
readonly providerAccounts?: readonly { readonly providerId: string; readonly accountId: string }[];
|
|
15
15
|
},
|
|
16
16
|
) {
|
|
17
|
-
const { test, internalAdapter } =
|
|
18
|
-
const user =
|
|
17
|
+
const { test, internalAdapter, sessionConfig } = yield* Effect.promise(() => auth.$context);
|
|
18
|
+
const user = yield* Effect.promise(() => test.saveUser(test.createUser(fields)));
|
|
19
19
|
for (const { providerId, accountId } of providerAccounts) {
|
|
20
|
-
|
|
20
|
+
yield* Effect.promise(() => internalAdapter.createAccount({ accountId, providerId, userId: user.id }));
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
}
|
|
22
|
+
const now = yield* Clock.currentTimeMillis;
|
|
23
|
+
const login = yield* Effect.promise(() => test.login({ userId: user.id }));
|
|
24
|
+
const expiresAt = new Date(now + sessionConfig.expiresIn * 1000);
|
|
25
|
+
yield* Effect.promise(() => internalAdapter.updateSession(login.token, { expiresAt }));
|
|
26
|
+
return { ...login, session: { ...login.session, expiresAt } };
|
|
27
|
+
});
|
|
24
28
|
|
|
25
29
|
export async function storedProviderAccounts(auth: { readonly $context: Promise<AccountContext> }, userId: string) {
|
|
26
30
|
const { internalAdapter } = await auth.$context;
|