@shivaedev/identity 0.7.0 → 0.8.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 +5 -4
- package/dist/server/better-auth/admittedSessions.d.ts +5 -2
- package/dist/server/better-auth/admittedSessions.d.ts.map +1 -1
- package/dist/server/better-auth/admittedSessions.js +5 -4
- package/dist/server/better-auth/admittedSessions.js.map +1 -1
- package/dist/server/better-auth/mount.d.ts +4 -1
- package/dist/server/better-auth/mount.d.ts.map +1 -1
- package/package.json +6 -4
- package/src/server/better-auth/admittedSessions.ts +15 -4
package/README.md
CHANGED
|
@@ -254,7 +254,7 @@ Here `sessions` is the application's policy from the previous example, with a Be
|
|
|
254
254
|
|
|
255
255
|
#### Reading provider account IDs
|
|
256
256
|
|
|
257
|
-
Pass Better Auth's account lookup as the second argument to `betterAuthSessions
|
|
257
|
+
Pass Better Auth's account lookup as the second argument to the mount's `admittedSessions` to combine provider accounts with its sign-in policy and credential selection. Without a mount, `betterAuthSessions` accepts the same two lookups. Declare `AuthenticatedUserWithProviderAccounts` on account-reading RPCs and merge `authenticatedUserWithProviderAccountsLayer(sessions)` alongside their handlers. This boundary requires a provider whose user has a `providerAccounts` Effect; a provider without the second lookup does not satisfy that type.
|
|
258
258
|
|
|
259
259
|
```ts
|
|
260
260
|
import { SessionUserWithProviderAccounts } from "@shivaedev/identity/identity.ts";
|
|
@@ -264,9 +264,10 @@ import { authenticatedUserWithProviderAccountsLayer } from "@shivaedev/identity/
|
|
|
264
264
|
|
|
265
265
|
const sessions = {
|
|
266
266
|
origin: trustedOrigins({ allow: ["https://app.example"], missing: "reject" }),
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
(headers) => auth.api.
|
|
267
|
+
...mounted.sessions,
|
|
268
|
+
provider: mounted.admittedSessions(
|
|
269
|
+
(headers) => mounted.auth.api.getSession({ headers }),
|
|
270
|
+
(headers) => mounted.auth.api.listUserAccounts({ headers }),
|
|
270
271
|
),
|
|
271
272
|
};
|
|
272
273
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type GetSession } from "#server/adapters/betterAuthSessions.ts";
|
|
1
|
+
import { type GetProviderAccounts, type GetSession, type SessionWithProviderAccounts } from "#server/adapters/betterAuthSessions.ts";
|
|
2
2
|
import type { SessionProvider, SessionShape } from "#server/session.ts";
|
|
3
3
|
import { type BearerSessionsOptions } from "./bearerSessions.ts";
|
|
4
4
|
import { type PolicyStorage, type SignInGate } from "./signInGate.ts";
|
|
@@ -9,6 +9,9 @@ interface SessionStorage extends PolicyStorage {
|
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
export declare function admittedSessions<E>(gate: SignInGate<E>, storage: () => Promise<SessionStorage>, bearerSessions?: BearerSessionsOptions):
|
|
12
|
+
export declare function admittedSessions<E>(gate: SignInGate<E>, storage: () => Promise<SessionStorage>, bearerSessions?: BearerSessionsOptions): {
|
|
13
|
+
<TSession extends SessionShape>(getSession: GetSession<TSession>): SessionProvider<TSession>;
|
|
14
|
+
<TSession extends SessionShape>(getSession: GetSession<TSession>, getProviderAccounts: GetProviderAccounts): SessionProvider<SessionWithProviderAccounts<TSession>>;
|
|
15
|
+
};
|
|
13
16
|
export {};
|
|
14
17
|
//# sourceMappingURL=admittedSessions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admittedSessions.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/admittedSessions.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"admittedSessions.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/admittedSessions.ts"],"names":[],"mappings":"AAEA,OAAO,EAEN,KAAK,mBAAmB,EACxB,KAAK,UAAU,EACf,KAAK,2BAA2B,EAChC,MAAM,wCAAwC,CAAC;AAEhD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,KAAK,qBAAqB,EAAkB,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAe,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEnF,UAAU,cAAe,SAAQ,aAAa;IAC7C,QAAQ,CAAC,WAAW,EAAE;QAAE,QAAQ,CAAC,YAAY,EAAE;YAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CAC3E;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC,EAAE,qBAAqB;KACvH,QAAQ,SAAS,YAAY,cAAc,UAAU,CAAC,QAAQ,CAAC,GAAG,eAAe,CAAC,QAAQ,CAAC;KAC3F,QAAQ,SAAS,YAAY,cAC/B,UAAU,CAAC,QAAQ,CAAC,uBACX,mBAAmB,GACtC,eAAe,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC;EA0BzD"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Effect, Option } from "effect";
|
|
2
2
|
import { Headers as HttpHeaders } from "effect/http";
|
|
3
|
-
import { betterAuthSessions } from "#server/adapters/betterAuthSessions.ts";
|
|
3
|
+
import { betterAuthSessions, } from "#server/adapters/betterAuthSessions.ts";
|
|
4
4
|
import { providerFailure } from "#server/providerFailure.ts";
|
|
5
5
|
import { sessionHeaders } from "./bearerSessions.js";
|
|
6
6
|
import { fromStorage } from "./signInGate.js";
|
|
7
7
|
export function admittedSessions(gate, storage, bearerSessions) {
|
|
8
|
-
|
|
9
|
-
const provider = betterAuthSessions(getSession);
|
|
8
|
+
function admit(getSession, getProviderAccounts) {
|
|
9
|
+
const provider = getProviderAccounts === undefined ? betterAuthSessions(getSession) : betterAuthSessions(getSession, getProviderAccounts);
|
|
10
10
|
return {
|
|
11
11
|
get: Effect.fnUntraced(function* (headers) {
|
|
12
12
|
const auth = gate.active || bearerSessions !== undefined ? yield* fromStorage(storage) : undefined;
|
|
@@ -27,6 +27,7 @@ export function admittedSessions(gate, storage, bearerSessions) {
|
|
|
27
27
|
return Option.none();
|
|
28
28
|
}),
|
|
29
29
|
};
|
|
30
|
-
}
|
|
30
|
+
}
|
|
31
|
+
return admit;
|
|
31
32
|
}
|
|
32
33
|
//# sourceMappingURL=admittedSessions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admittedSessions.js","sourceRoot":"","sources":["../../../src/server/better-auth/admittedSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"admittedSessions.js","sourceRoot":"","sources":["../../../src/server/better-auth/admittedSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EACN,kBAAkB,GAIlB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAA8B,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,WAAW,EAAuC,MAAM,iBAAiB,CAAC;AAMnF,MAAM,UAAU,gBAAgB,CAAI,IAAmB,EAAE,OAAsC,EAAE,cAAsC;IAMtI,SAAS,KAAK,CAAgC,UAAgC,EAAE,mBAAyC;QACxH,MAAM,QAAQ,GAAG,mBAAmB,KAAK,SAAS,CAAC,CAAC,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;QAC1I,OAAO;YACN,GAAG,EA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M,EAAE,CAAC,CAAC,CAAC;gBAC5G,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;YACtB,CAAC,CAAC;SACF,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -10,7 +10,10 @@ export interface BetterAuthMountOptions<E = never, R = never> {
|
|
|
10
10
|
readonly signIn?: SignInPolicy<E, R> | undefined;
|
|
11
11
|
}
|
|
12
12
|
export declare const betterAuthMount: <const TOptions extends BetterAuthOptions, E = never, R = never>(options: TOptions, mount?: BetterAuthMountOptions<E, R> | undefined) => Effect.Effect<{
|
|
13
|
-
admittedSessions:
|
|
13
|
+
admittedSessions: {
|
|
14
|
+
<TSession extends import("../session.ts").SessionShape>(getSession: import("../adapters/betterAuthSessions.ts").GetSession<TSession>): import("../session.ts").SessionProvider<TSession>;
|
|
15
|
+
<TSession extends import("../session.ts").SessionShape>(getSession: import("../adapters/betterAuthSessions.ts").GetSession<TSession>, getProviderAccounts: import("../adapters/betterAuthSessions.ts").GetProviderAccounts): import("../session.ts").SessionProvider<import("../adapters/betterAuthSessions.ts").SessionWithProviderAccounts<TSession>>;
|
|
16
|
+
};
|
|
14
17
|
auth: import("better-auth").Auth<TOptions & {
|
|
15
18
|
advanced: {
|
|
16
19
|
disableCSRFCheck?: boolean | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/mount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAU,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAmB,KAAK,UAAU,EAAE,MAAM,IAAI,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,KAAK,qBAAqB,EAAsB,MAAM,uCAAuC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B,EAAE,CAAC,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wDA6DpI,CAAC;AAEH,eAAO,MAAM,YAAY,kKAgCvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/identity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Request identity, sessions, transport trust and permission enforcement for Effect RPC servers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@shivaedev/access": "0.2.0",
|
|
48
48
|
"@shivaedev/changes": "0.5.1",
|
|
49
|
-
"@shivaedev/contract": "0.
|
|
49
|
+
"@shivaedev/contract": "0.24.0",
|
|
50
50
|
"@shivaedev/errors": "0.1.2",
|
|
51
51
|
"@shivaedev/sql": "0.26.1"
|
|
52
52
|
},
|
|
@@ -54,8 +54,10 @@
|
|
|
54
54
|
"@effect/platform-node": "4.0.6",
|
|
55
55
|
"@effect/sql-pg": "4.0.6",
|
|
56
56
|
"@shivaedev/quality": "0.47.0",
|
|
57
|
-
"@shivaedev/
|
|
58
|
-
"@shivaedev/test
|
|
57
|
+
"@shivaedev/server": "0.9.0",
|
|
58
|
+
"@shivaedev/test": "0.12.0",
|
|
59
|
+
"@shivaedev/test-sql": "0.14.0",
|
|
60
|
+
"@shivaedev/test-story": "0.26.1",
|
|
59
61
|
"@types/node": "24.19.2",
|
|
60
62
|
"@types/pg": "8.20.0",
|
|
61
63
|
"better-auth": "1.7.12",
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Effect, Option } from "effect";
|
|
2
2
|
import { Headers as HttpHeaders } from "effect/http";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
betterAuthSessions,
|
|
5
|
+
type GetProviderAccounts,
|
|
6
|
+
type GetSession,
|
|
7
|
+
type SessionWithProviderAccounts,
|
|
8
|
+
} from "#server/adapters/betterAuthSessions.ts";
|
|
4
9
|
import { providerFailure } from "#server/providerFailure.ts";
|
|
5
10
|
import type { SessionProvider, SessionShape } from "#server/session.ts";
|
|
6
11
|
import { type BearerSessionsOptions, sessionHeaders } from "./bearerSessions.ts";
|
|
@@ -11,8 +16,13 @@ interface SessionStorage extends PolicyStorage {
|
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
export function admittedSessions<E>(gate: SignInGate<E>, storage: () => Promise<SessionStorage>, bearerSessions?: BearerSessionsOptions) {
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
function admit<TSession extends SessionShape>(getSession: GetSession<TSession>): SessionProvider<TSession>;
|
|
20
|
+
function admit<TSession extends SessionShape>(
|
|
21
|
+
getSession: GetSession<TSession>,
|
|
22
|
+
getProviderAccounts: GetProviderAccounts,
|
|
23
|
+
): SessionProvider<SessionWithProviderAccounts<TSession>>;
|
|
24
|
+
function admit<TSession extends SessionShape>(getSession: GetSession<TSession>, getProviderAccounts?: GetProviderAccounts) {
|
|
25
|
+
const provider = getProviderAccounts === undefined ? betterAuthSessions(getSession) : betterAuthSessions(getSession, getProviderAccounts);
|
|
16
26
|
return {
|
|
17
27
|
get: Effect.fnUntraced(function* (headers) {
|
|
18
28
|
const auth = gate.active || bearerSessions !== undefined ? yield* fromStorage(storage) : undefined;
|
|
@@ -34,5 +44,6 @@ export function admittedSessions<E>(gate: SignInGate<E>, storage: () => Promise<
|
|
|
34
44
|
return Option.none();
|
|
35
45
|
}),
|
|
36
46
|
};
|
|
37
|
-
}
|
|
47
|
+
}
|
|
48
|
+
return admit;
|
|
38
49
|
}
|