@krak-stack/auth 0.1.70 → 0.1.71
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/dist/components/admin-organizations.js +0 -1
- package/dist/components/admin-users.js +0 -1
- package/dist/components/organization-switcher.js +0 -1
- package/dist/components/user-button.js +1 -2
- package/dist/server/actor.d.ts +10 -10
- package/dist/server/actor.js +25 -5
- package/dist/server/middleware.d.ts +2 -2
- package/dist/server/middleware.js +9 -4
- package/dist/service.d.ts +10 -10
- package/dist/service.js +9 -5
- package/package.json +3 -3
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
3
|
-
import {} from "@tanstack/react-table";
|
|
4
3
|
import { Atom, AsyncResult } from "effect/unstable/reactivity";
|
|
5
4
|
import { Building2, Pencil, Trash2 } from "lucide-react";
|
|
6
5
|
import { useState } from "react";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
3
3
|
import { useNavigate, useRouter, } from "@tanstack/react-router";
|
|
4
|
-
import {} from "@tanstack/react-table";
|
|
5
4
|
import { Atom, AsyncResult } from "effect/unstable/reactivity";
|
|
6
5
|
import { Ban, Building2, Loader2, ShieldOff, UserCog, UserIcon, } from "lucide-react";
|
|
7
6
|
import { useState } from "react";
|
|
@@ -2,7 +2,6 @@ import { createElement as _createElement } from "react";
|
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useAtomRefresh, useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
4
4
|
import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
|
|
5
|
-
import {} from "@tanstack/react-table";
|
|
6
5
|
import { Effect, Option, Schema } from "effect";
|
|
7
6
|
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
8
7
|
import { ArrowLeft, Building2, Check, ChevronsUpDown, Copy, KeyRound, LogOut, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useAtomRefresh, useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
3
3
|
import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
|
|
4
|
-
import {} from "@tanstack/react-table";
|
|
5
4
|
import { useNavigate, useRouterState, } from "@tanstack/react-router";
|
|
6
5
|
import { Effect, Schema } from "effect";
|
|
7
6
|
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
8
7
|
import { ArrowLeft, Building2, KeyRound, Loader2, LogOutIcon, Pencil, Plus, ShieldCheck, StopCircle, Trash2, UserCircleIcon, Users, UserIcon, } from "lucide-react";
|
|
9
8
|
import { QRCode } from "react-qr-code";
|
|
10
9
|
import { createContext, useContext, useRef, useState, } from "react";
|
|
11
|
-
import { DataTable } from "@krak-stack/registry/data-table";
|
|
10
|
+
import { DataTable, } from "@krak-stack/registry/data-table";
|
|
12
11
|
import { AppBrand } from "@krak-stack/registry/app-brand";
|
|
13
12
|
import { effectFormMessages, ImageField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
|
|
14
13
|
import { Badge } from "@/components/ui/badge";
|
package/dist/server/actor.d.ts
CHANGED
|
@@ -5,51 +5,51 @@ import { AuthService } from "../service";
|
|
|
5
5
|
declare const AnyActorRequired_base: HttpApiMiddleware.ServiceClass<AnyActorRequired, "@krak-stack/auth/ActorRequired", {
|
|
6
6
|
requires: AuthService;
|
|
7
7
|
provides: CurrentActor;
|
|
8
|
-
error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden];
|
|
8
|
+
error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable];
|
|
9
9
|
clientError: never;
|
|
10
10
|
requiredForClient: false;
|
|
11
11
|
security: never;
|
|
12
|
-
}, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden], AuthService>>;
|
|
12
|
+
}, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable], AuthService>>;
|
|
13
13
|
declare class AnyActorRequired extends AnyActorRequired_base {
|
|
14
14
|
}
|
|
15
15
|
declare const UserActorRequired_base: HttpApiMiddleware.ServiceClass<UserActorRequired, "@krak-stack/auth/ActorRequired/User", {
|
|
16
16
|
requires: AuthService;
|
|
17
17
|
provides: CurrentActor;
|
|
18
|
-
error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden];
|
|
18
|
+
error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable];
|
|
19
19
|
clientError: never;
|
|
20
20
|
requiredForClient: false;
|
|
21
21
|
security: never;
|
|
22
|
-
}, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden], AuthService>>;
|
|
22
|
+
}, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable], AuthService>>;
|
|
23
23
|
declare class UserActorRequired extends UserActorRequired_base {
|
|
24
24
|
}
|
|
25
25
|
declare const ApiKeyActorRequired_base: HttpApiMiddleware.ServiceClass<ApiKeyActorRequired, "@krak-stack/auth/ActorRequired/ApiKey", {
|
|
26
26
|
requires: AuthService;
|
|
27
27
|
provides: CurrentActor;
|
|
28
|
-
error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden];
|
|
28
|
+
error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable];
|
|
29
29
|
clientError: never;
|
|
30
30
|
requiredForClient: false;
|
|
31
31
|
security: never;
|
|
32
|
-
}, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden], AuthService>>;
|
|
32
|
+
}, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable], AuthService>>;
|
|
33
33
|
declare class ApiKeyActorRequired extends ApiKeyActorRequired_base {
|
|
34
34
|
}
|
|
35
35
|
declare const UserApiKeyActorRequired_base: HttpApiMiddleware.ServiceClass<UserApiKeyActorRequired, "@krak-stack/auth/ActorRequired/ApiKey/User", {
|
|
36
36
|
requires: AuthService;
|
|
37
37
|
provides: CurrentActor;
|
|
38
|
-
error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden];
|
|
38
|
+
error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable];
|
|
39
39
|
clientError: never;
|
|
40
40
|
requiredForClient: false;
|
|
41
41
|
security: never;
|
|
42
|
-
}, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden], AuthService>>;
|
|
42
|
+
}, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable], AuthService>>;
|
|
43
43
|
declare class UserApiKeyActorRequired extends UserApiKeyActorRequired_base {
|
|
44
44
|
}
|
|
45
45
|
declare const OrganizationApiKeyActorRequired_base: HttpApiMiddleware.ServiceClass<OrganizationApiKeyActorRequired, "@krak-stack/auth/ActorRequired/ApiKey/Organization", {
|
|
46
46
|
requires: AuthService;
|
|
47
47
|
provides: CurrentActor;
|
|
48
|
-
error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden];
|
|
48
|
+
error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable];
|
|
49
49
|
clientError: never;
|
|
50
50
|
requiredForClient: false;
|
|
51
51
|
security: never;
|
|
52
|
-
}, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden], AuthService>>;
|
|
52
|
+
}, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable], AuthService>>;
|
|
53
53
|
declare class OrganizationApiKeyActorRequired extends OrganizationApiKeyActorRequired_base {
|
|
54
54
|
}
|
|
55
55
|
export type ActorConstraint = {
|
package/dist/server/actor.js
CHANGED
|
@@ -60,23 +60,43 @@ const resolveCurrentActor = (access) => Effect.gen(function* () {
|
|
|
60
60
|
});
|
|
61
61
|
});
|
|
62
62
|
class AnyActorRequired extends HttpApiMiddleware.Service()("@krak-stack/auth/ActorRequired", {
|
|
63
|
-
error: [
|
|
63
|
+
error: [
|
|
64
|
+
HttpApiError.Unauthorized,
|
|
65
|
+
HttpApiError.Forbidden,
|
|
66
|
+
HttpApiError.ServiceUnavailable,
|
|
67
|
+
],
|
|
64
68
|
}) {
|
|
65
69
|
}
|
|
66
70
|
class UserActorRequired extends HttpApiMiddleware.Service()("@krak-stack/auth/ActorRequired/User", {
|
|
67
|
-
error: [
|
|
71
|
+
error: [
|
|
72
|
+
HttpApiError.Unauthorized,
|
|
73
|
+
HttpApiError.Forbidden,
|
|
74
|
+
HttpApiError.ServiceUnavailable,
|
|
75
|
+
],
|
|
68
76
|
}) {
|
|
69
77
|
}
|
|
70
78
|
class ApiKeyActorRequired extends HttpApiMiddleware.Service()("@krak-stack/auth/ActorRequired/ApiKey", {
|
|
71
|
-
error: [
|
|
79
|
+
error: [
|
|
80
|
+
HttpApiError.Unauthorized,
|
|
81
|
+
HttpApiError.Forbidden,
|
|
82
|
+
HttpApiError.ServiceUnavailable,
|
|
83
|
+
],
|
|
72
84
|
}) {
|
|
73
85
|
}
|
|
74
86
|
class UserApiKeyActorRequired extends HttpApiMiddleware.Service()("@krak-stack/auth/ActorRequired/ApiKey/User", {
|
|
75
|
-
error: [
|
|
87
|
+
error: [
|
|
88
|
+
HttpApiError.Unauthorized,
|
|
89
|
+
HttpApiError.Forbidden,
|
|
90
|
+
HttpApiError.ServiceUnavailable,
|
|
91
|
+
],
|
|
76
92
|
}) {
|
|
77
93
|
}
|
|
78
94
|
class OrganizationApiKeyActorRequired extends HttpApiMiddleware.Service()("@krak-stack/auth/ActorRequired/ApiKey/Organization", {
|
|
79
|
-
error: [
|
|
95
|
+
error: [
|
|
96
|
+
HttpApiError.Unauthorized,
|
|
97
|
+
HttpApiError.Forbidden,
|
|
98
|
+
HttpApiError.ServiceUnavailable,
|
|
99
|
+
],
|
|
80
100
|
}) {
|
|
81
101
|
}
|
|
82
102
|
const matchesConstraint = (actor, constraint) => {
|
|
@@ -6,7 +6,7 @@ export declare const ApiKeySecurity: HttpApiSecurity.ApiKey;
|
|
|
6
6
|
declare const AuthMiddleware_base: HttpApiMiddleware.ServiceClass<AuthMiddleware, "@krak-stack/auth/AuthMiddleware", {
|
|
7
7
|
requires: never;
|
|
8
8
|
provides: AuthService;
|
|
9
|
-
error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden];
|
|
9
|
+
error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable];
|
|
10
10
|
clientError: never;
|
|
11
11
|
requiredForClient: false;
|
|
12
12
|
security: {
|
|
@@ -14,7 +14,7 @@ declare const AuthMiddleware_base: HttpApiMiddleware.ServiceClass<AuthMiddleware
|
|
|
14
14
|
};
|
|
15
15
|
}, HttpApiMiddleware.HttpApiMiddlewareSecurity<{
|
|
16
16
|
readonly apiKey: HttpApiSecurity.ApiKey;
|
|
17
|
-
}, AuthService, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden], never>>;
|
|
17
|
+
}, AuthService, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable], never>>;
|
|
18
18
|
export declare class AuthMiddleware extends AuthMiddleware_base {
|
|
19
19
|
static readonly layer: (options?: AuthenticationLiveOptions | Layer.Layer<AuthService, unknown>) => Layer.Layer<AuthMiddleware, never, never>;
|
|
20
20
|
}
|
|
@@ -7,7 +7,11 @@ export const ApiKeySecurity = HttpApiSecurity.apiKey({
|
|
|
7
7
|
in: "header",
|
|
8
8
|
});
|
|
9
9
|
export class AuthMiddleware extends HttpApiMiddleware.Service()("@krak-stack/auth/AuthMiddleware", {
|
|
10
|
-
error: [
|
|
10
|
+
error: [
|
|
11
|
+
HttpApiError.Unauthorized,
|
|
12
|
+
HttpApiError.Forbidden,
|
|
13
|
+
HttpApiError.ServiceUnavailable,
|
|
14
|
+
],
|
|
11
15
|
security: {
|
|
12
16
|
apiKey: ApiKeySecurity,
|
|
13
17
|
},
|
|
@@ -32,7 +36,7 @@ export const makeAuthenticationLive = (options = {}) => {
|
|
|
32
36
|
AuthService.layer({
|
|
33
37
|
...authOptions,
|
|
34
38
|
headers,
|
|
35
|
-
})), Effect.tapCause((cause) => Effect.logError("Authentication rejected: auth client initialization failed", Cause.pretty(cause))), Effect.mapError(() => new HttpApiError.
|
|
39
|
+
})), Effect.tapCause((cause) => Effect.logError("Authentication rejected: auth client initialization failed", Cause.pretty(cause))), Effect.mapError(() => new HttpApiError.ServiceUnavailable({})));
|
|
36
40
|
if (!isAllowedRoute(allowedOrganizationImpersonationRoutes, request)) {
|
|
37
41
|
const session = yield* auth
|
|
38
42
|
.getSession()
|
|
@@ -43,9 +47,10 @@ export const makeAuthenticationLive = (options = {}) => {
|
|
|
43
47
|
}
|
|
44
48
|
return auth;
|
|
45
49
|
}).pipe(Effect.mapError((error) => error instanceof HttpApiError.Unauthorized ||
|
|
46
|
-
error instanceof HttpApiError.Forbidden
|
|
50
|
+
error instanceof HttpApiError.Forbidden ||
|
|
51
|
+
error instanceof HttpApiError.ServiceUnavailable
|
|
47
52
|
? error
|
|
48
|
-
: new HttpApiError.
|
|
53
|
+
: new HttpApiError.ServiceUnavailable({})), Effect.flatMap((auth) => httpEffect.pipe(Effect.provideService(AuthService, auth)))),
|
|
49
54
|
};
|
|
50
55
|
}));
|
|
51
56
|
};
|
package/dist/service.d.ts
CHANGED
|
@@ -31,11 +31,11 @@ export type AuthServiceLayerOptions = Partial<ClientConfig> & {
|
|
|
31
31
|
readonly apiKeyConfigId?: "user" | "organization" | "service";
|
|
32
32
|
};
|
|
33
33
|
declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/auth/AuthService", {
|
|
34
|
-
getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized
|
|
35
|
-
requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized>;
|
|
36
|
-
requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized>;
|
|
37
|
-
requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized>;
|
|
38
|
-
requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized>;
|
|
34
|
+
getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
35
|
+
requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
36
|
+
requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
37
|
+
requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
38
|
+
requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
39
39
|
auth: {
|
|
40
40
|
readonly getSession: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: void | {
|
|
41
41
|
readonly responseMode?: Mode;
|
|
@@ -661,11 +661,11 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
661
661
|
};
|
|
662
662
|
}> & {
|
|
663
663
|
readonly make: (options?: AuthServiceLayerOptions) => Effect.Effect<{
|
|
664
|
-
getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized
|
|
665
|
-
requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized>;
|
|
666
|
-
requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized>;
|
|
667
|
-
requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized>;
|
|
668
|
-
requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized>;
|
|
664
|
+
getSession: () => Effect.Effect<AuthSession | null, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
665
|
+
requireSession: () => Effect.Effect<AuthSession, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
666
|
+
requireUser: () => Effect.Effect<AuthSessionWithUser, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
667
|
+
requireOrganization: () => Effect.Effect<AuthSessionWithOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
668
|
+
requireUserOrganization: () => Effect.Effect<AuthSessionWithUserAndOrganization, HttpApiError.Unauthorized | HttpApiError.ServiceUnavailable>;
|
|
669
669
|
auth: {
|
|
670
670
|
readonly getSession: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: void | {
|
|
671
671
|
readonly responseMode?: Mode;
|
package/dist/service.js
CHANGED
|
@@ -36,6 +36,7 @@ const headerValue = (headers, name) => {
|
|
|
36
36
|
return entry?.[1];
|
|
37
37
|
};
|
|
38
38
|
const unauthorized = () => new HttpApiError.Unauthorized({});
|
|
39
|
+
const serviceUnavailable = () => new HttpApiError.ServiceUnavailable({});
|
|
39
40
|
const withRequiredOrganization = (authSession) => {
|
|
40
41
|
const activeOrganizationId = authSession.session.activeOrganizationId;
|
|
41
42
|
return activeOrganizationId
|
|
@@ -71,9 +72,10 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
71
72
|
});
|
|
72
73
|
const sessionCacheKey = getSessionCacheKey(headers);
|
|
73
74
|
const apiKey = headerValue(headers, "x-api-key")?.trim();
|
|
75
|
+
const organizationId = headerValue(headers, "x-organization-id")?.trim();
|
|
74
76
|
const getCookieSession = () => Cache.get(sessionCache, sessionCacheKey).pipe(Effect.provideService(SessionLookup, {
|
|
75
77
|
getSession: api.auth.getSession,
|
|
76
|
-
}), Effect.mapError(
|
|
78
|
+
}), Effect.mapError(serviceUnavailable), Effect.map((authSession) => authSession
|
|
77
79
|
? {
|
|
78
80
|
...authSession,
|
|
79
81
|
isSuperAdminImpersonation: false,
|
|
@@ -86,17 +88,19 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
86
88
|
}
|
|
87
89
|
return api.users
|
|
88
90
|
.getUser({ params: { id: verifiedKey.referenceId } })
|
|
89
|
-
.pipe(Effect.mapError(
|
|
91
|
+
.pipe(Effect.mapError(serviceUnavailable));
|
|
90
92
|
};
|
|
91
93
|
const activeOrganizationIdForApiKey = (verifiedKey, user) => {
|
|
92
94
|
if (verifiedKey.configId === "organization") {
|
|
93
95
|
return Effect.succeed({ id: verifiedKey.referenceId });
|
|
94
96
|
}
|
|
97
|
+
if (organizationId)
|
|
98
|
+
return Effect.succeed({ id: organizationId });
|
|
95
99
|
if (!user)
|
|
96
100
|
return Effect.succeed({ id: null });
|
|
97
101
|
return api.users
|
|
98
102
|
.getUserActiveOrganization({ params: { userId: user.id } })
|
|
99
|
-
.pipe(Effect.
|
|
103
|
+
.pipe(Effect.mapError(serviceUnavailable));
|
|
100
104
|
};
|
|
101
105
|
const getApiKeySession = (key) => Effect.gen(function* () {
|
|
102
106
|
const verified = yield* api.authExtra
|
|
@@ -106,7 +110,7 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
106
110
|
...(apiKeyConfigId ? { configId: apiKeyConfigId } : {}),
|
|
107
111
|
},
|
|
108
112
|
})
|
|
109
|
-
.pipe(Effect.mapError(
|
|
113
|
+
.pipe(Effect.mapError(serviceUnavailable));
|
|
110
114
|
if (!verified.valid || !verified.key) {
|
|
111
115
|
return yield* Effect.fail(unauthorized());
|
|
112
116
|
}
|
|
@@ -131,7 +135,7 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
|
|
|
131
135
|
},
|
|
132
136
|
};
|
|
133
137
|
});
|
|
134
|
-
const getSession = () => apiKey ? getApiKeySession(apiKey) : getCookieSession();
|
|
138
|
+
const getSession = () => (apiKey ? getApiKeySession(apiKey) : getCookieSession());
|
|
135
139
|
const requireSession = () => getSession().pipe(Effect.flatMap((authSession) => authSession
|
|
136
140
|
? Effect.succeed(authSession)
|
|
137
141
|
: Effect.fail(unauthorized())));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.71",
|
|
4
4
|
"description": "Effect HttpApi clients and schemas for KrakStack Auth.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -75,13 +75,13 @@
|
|
|
75
75
|
"type:check": "tsc -p tsconfig.json --noEmit"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@krak-stack/registry": "
|
|
78
|
+
"@krak-stack/registry": "0.1.19",
|
|
79
79
|
"react-qr-code": "^2.2.0"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
82
|
"@better-auth/api-key": "^1.6.14",
|
|
83
83
|
"@tanstack/react-router": "^1.170.15",
|
|
84
|
-
"@tanstack/react-table": "^
|
|
84
|
+
"@tanstack/react-table": "^9.1.2",
|
|
85
85
|
"better-auth": "^1.6.14",
|
|
86
86
|
"effect": "^4.0.0-beta.78",
|
|
87
87
|
"input-otp": "^1.4.2",
|