@korajs/auth 0.4.0 → 0.6.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 +81 -28
- package/dist/chunk-7OXBRSJL.js +203 -0
- package/dist/chunk-7OXBRSJL.js.map +1 -0
- package/dist/create-org-session-RsDj9cl4.d.cts +722 -0
- package/dist/create-org-session-RsDj9cl4.d.ts +722 -0
- package/dist/index.cjs +1146 -586
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -118
- package/dist/index.d.ts +67 -118
- package/dist/index.js +654 -258
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +297 -183
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +25 -209
- package/dist/react.d.ts +25 -209
- package/dist/react.js +134 -209
- package/dist/react.js.map +1 -1
- package/dist/server.cjs +1611 -730
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +415 -224
- package/dist/server.d.ts +415 -224
- package/dist/server.js +1565 -704
- package/dist/server.js.map +1 -1
- package/dist/svelte.cjs +512 -0
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.d.cts +100 -0
- package/dist/svelte.d.ts +100 -0
- package/dist/svelte.js +278 -0
- package/dist/svelte.js.map +1 -0
- package/dist/vue.cjs +565 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +136 -0
- package/dist/vue.d.ts +136 -0
- package/dist/vue.js +338 -0
- package/dist/vue.js.map +1 -0
- package/package.json +40 -6
- package/src/svelte/AuthProvider.svelte +37 -0
- package/src/svelte/OrgProvider.svelte +22 -0
- package/dist/org-client-BVTLKcIk.d.cts +0 -355
- package/dist/org-client-BVTLKcIk.d.ts +0 -355
package/dist/vue.d.cts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { PropType, VNode } from 'vue';
|
|
3
|
+
import { d as AuthClient, e as AuthState, i as AuthSession, l as AuthUser, O as OAuthAuthorizationOptions, q as OAuthAuthorizationResult, r as OAuthCallbackParams, L as LinkedOAuthAccount, s as OrgClient, v as OrgSession, m as ClientMembership, C as ClientInvitation, n as ClientOrganization } from './create-org-session-RsDj9cl4.cjs';
|
|
4
|
+
import '@korajs/core';
|
|
5
|
+
|
|
6
|
+
interface AuthContextValue {
|
|
7
|
+
client: AuthClient;
|
|
8
|
+
state: AuthState;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
session: AuthSession;
|
|
11
|
+
}
|
|
12
|
+
declare const authContextKey: unique symbol;
|
|
13
|
+
|
|
14
|
+
declare const AuthProvider: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
15
|
+
client: {
|
|
16
|
+
type: PropType<AuthClient>;
|
|
17
|
+
required: true;
|
|
18
|
+
};
|
|
19
|
+
fallback: {
|
|
20
|
+
type: PropType<VNode | string | null>;
|
|
21
|
+
default: null;
|
|
22
|
+
};
|
|
23
|
+
}>, () => string | VNode<vue.RendererNode, vue.RendererElement, {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}> | VNode<vue.RendererNode, vue.RendererElement, {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}>[] | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
28
|
+
client: {
|
|
29
|
+
type: PropType<AuthClient>;
|
|
30
|
+
required: true;
|
|
31
|
+
};
|
|
32
|
+
fallback: {
|
|
33
|
+
type: PropType<VNode | string | null>;
|
|
34
|
+
default: null;
|
|
35
|
+
};
|
|
36
|
+
}>> & Readonly<{}>, {
|
|
37
|
+
fallback: string | VNode<vue.RendererNode, vue.RendererElement, {
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
}> | null;
|
|
40
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
41
|
+
declare function useAuthContext(): AuthContextValue;
|
|
42
|
+
|
|
43
|
+
/** Props for {@link AuthProvider}. */
|
|
44
|
+
interface AuthProviderProps {
|
|
45
|
+
client: AuthClient;
|
|
46
|
+
fallback?: vue.VNode | string | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface UseAuthResult {
|
|
50
|
+
user: AuthUser | null;
|
|
51
|
+
isAuthenticated: boolean;
|
|
52
|
+
isLoading: boolean;
|
|
53
|
+
signUp: (params: {
|
|
54
|
+
email: string;
|
|
55
|
+
password: string;
|
|
56
|
+
name?: string;
|
|
57
|
+
deviceId?: string;
|
|
58
|
+
devicePublicKey?: string;
|
|
59
|
+
}) => Promise<void>;
|
|
60
|
+
signIn: (params: {
|
|
61
|
+
email: string;
|
|
62
|
+
password: string;
|
|
63
|
+
deviceId?: string;
|
|
64
|
+
devicePublicKey?: string;
|
|
65
|
+
}) => Promise<void>;
|
|
66
|
+
signInWithOAuth: (provider: string, options?: OAuthAuthorizationOptions) => Promise<OAuthAuthorizationResult>;
|
|
67
|
+
completeOAuthSignIn: (provider: string, params: OAuthCallbackParams) => Promise<void>;
|
|
68
|
+
getOAuthAuthorizationUrl: (provider: string, options?: OAuthAuthorizationOptions) => Promise<OAuthAuthorizationResult>;
|
|
69
|
+
linkOAuth: (provider: string, params: OAuthCallbackParams) => Promise<LinkedOAuthAccount | null>;
|
|
70
|
+
listLinkedAccounts: () => Promise<LinkedOAuthAccount[]>;
|
|
71
|
+
unlinkOAuth: (provider: string) => Promise<void>;
|
|
72
|
+
signOut: () => Promise<void>;
|
|
73
|
+
error: string | null;
|
|
74
|
+
}
|
|
75
|
+
interface AuthStatus {
|
|
76
|
+
state: AuthState;
|
|
77
|
+
isAuthenticated: boolean;
|
|
78
|
+
isLoading: boolean;
|
|
79
|
+
}
|
|
80
|
+
declare function useAuth(): UseAuthResult;
|
|
81
|
+
declare function useCurrentUser(): vue.ComputedRef<{
|
|
82
|
+
id: string;
|
|
83
|
+
email: string;
|
|
84
|
+
name: string | null;
|
|
85
|
+
} | null>;
|
|
86
|
+
declare function useAuthStatus(): AuthStatus;
|
|
87
|
+
|
|
88
|
+
interface OrgContextValue {
|
|
89
|
+
client: OrgClient;
|
|
90
|
+
session: OrgSession;
|
|
91
|
+
}
|
|
92
|
+
declare const OrgProvider: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
93
|
+
client: {
|
|
94
|
+
type: PropType<OrgClient>;
|
|
95
|
+
required: true;
|
|
96
|
+
};
|
|
97
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
98
|
+
[key: string]: any;
|
|
99
|
+
}>[] | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
100
|
+
client: {
|
|
101
|
+
type: PropType<OrgClient>;
|
|
102
|
+
required: true;
|
|
103
|
+
};
|
|
104
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
105
|
+
declare function useOrgContext(): OrgContextValue;
|
|
106
|
+
|
|
107
|
+
interface UseOrgResult {
|
|
108
|
+
org: ClientOrganization | null;
|
|
109
|
+
role: string | null;
|
|
110
|
+
orgId: string | null;
|
|
111
|
+
switchOrg: (orgId: string) => Promise<void>;
|
|
112
|
+
createOrg: (params: {
|
|
113
|
+
name: string;
|
|
114
|
+
slug?: string;
|
|
115
|
+
}) => Promise<ClientOrganization>;
|
|
116
|
+
leaveOrg: () => Promise<void>;
|
|
117
|
+
clearOrg: () => void;
|
|
118
|
+
listOrgs: () => Promise<ClientOrganization[]>;
|
|
119
|
+
error: string | null;
|
|
120
|
+
}
|
|
121
|
+
interface UseOrgMembersResult {
|
|
122
|
+
members: ClientMembership[];
|
|
123
|
+
isLoading: boolean;
|
|
124
|
+
refresh: () => Promise<void>;
|
|
125
|
+
invite: (email: string, role: string) => Promise<ClientInvitation>;
|
|
126
|
+
removeMember: (userId: string) => Promise<void>;
|
|
127
|
+
updateRole: (userId: string, role: string) => Promise<void>;
|
|
128
|
+
error: string | null;
|
|
129
|
+
}
|
|
130
|
+
declare function useOrg(): UseOrgResult;
|
|
131
|
+
declare function useOrgMembers(orgId: string): UseOrgMembersResult;
|
|
132
|
+
declare function usePermission(requiredRole: string): Readonly<{
|
|
133
|
+
value: boolean;
|
|
134
|
+
}>;
|
|
135
|
+
|
|
136
|
+
export { type AuthContextValue, AuthProvider, type AuthProviderProps, type AuthStatus, type OrgContextValue, OrgProvider, type UseAuthResult, type UseOrgMembersResult, type UseOrgResult, authContextKey, useAuth, useAuthContext, useAuthStatus, useCurrentUser, useOrg, useOrgContext, useOrgMembers, usePermission };
|
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { PropType, VNode } from 'vue';
|
|
3
|
+
import { d as AuthClient, e as AuthState, i as AuthSession, l as AuthUser, O as OAuthAuthorizationOptions, q as OAuthAuthorizationResult, r as OAuthCallbackParams, L as LinkedOAuthAccount, s as OrgClient, v as OrgSession, m as ClientMembership, C as ClientInvitation, n as ClientOrganization } from './create-org-session-RsDj9cl4.js';
|
|
4
|
+
import '@korajs/core';
|
|
5
|
+
|
|
6
|
+
interface AuthContextValue {
|
|
7
|
+
client: AuthClient;
|
|
8
|
+
state: AuthState;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
session: AuthSession;
|
|
11
|
+
}
|
|
12
|
+
declare const authContextKey: unique symbol;
|
|
13
|
+
|
|
14
|
+
declare const AuthProvider: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
15
|
+
client: {
|
|
16
|
+
type: PropType<AuthClient>;
|
|
17
|
+
required: true;
|
|
18
|
+
};
|
|
19
|
+
fallback: {
|
|
20
|
+
type: PropType<VNode | string | null>;
|
|
21
|
+
default: null;
|
|
22
|
+
};
|
|
23
|
+
}>, () => string | VNode<vue.RendererNode, vue.RendererElement, {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}> | VNode<vue.RendererNode, vue.RendererElement, {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}>[] | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
28
|
+
client: {
|
|
29
|
+
type: PropType<AuthClient>;
|
|
30
|
+
required: true;
|
|
31
|
+
};
|
|
32
|
+
fallback: {
|
|
33
|
+
type: PropType<VNode | string | null>;
|
|
34
|
+
default: null;
|
|
35
|
+
};
|
|
36
|
+
}>> & Readonly<{}>, {
|
|
37
|
+
fallback: string | VNode<vue.RendererNode, vue.RendererElement, {
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
}> | null;
|
|
40
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
41
|
+
declare function useAuthContext(): AuthContextValue;
|
|
42
|
+
|
|
43
|
+
/** Props for {@link AuthProvider}. */
|
|
44
|
+
interface AuthProviderProps {
|
|
45
|
+
client: AuthClient;
|
|
46
|
+
fallback?: vue.VNode | string | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface UseAuthResult {
|
|
50
|
+
user: AuthUser | null;
|
|
51
|
+
isAuthenticated: boolean;
|
|
52
|
+
isLoading: boolean;
|
|
53
|
+
signUp: (params: {
|
|
54
|
+
email: string;
|
|
55
|
+
password: string;
|
|
56
|
+
name?: string;
|
|
57
|
+
deviceId?: string;
|
|
58
|
+
devicePublicKey?: string;
|
|
59
|
+
}) => Promise<void>;
|
|
60
|
+
signIn: (params: {
|
|
61
|
+
email: string;
|
|
62
|
+
password: string;
|
|
63
|
+
deviceId?: string;
|
|
64
|
+
devicePublicKey?: string;
|
|
65
|
+
}) => Promise<void>;
|
|
66
|
+
signInWithOAuth: (provider: string, options?: OAuthAuthorizationOptions) => Promise<OAuthAuthorizationResult>;
|
|
67
|
+
completeOAuthSignIn: (provider: string, params: OAuthCallbackParams) => Promise<void>;
|
|
68
|
+
getOAuthAuthorizationUrl: (provider: string, options?: OAuthAuthorizationOptions) => Promise<OAuthAuthorizationResult>;
|
|
69
|
+
linkOAuth: (provider: string, params: OAuthCallbackParams) => Promise<LinkedOAuthAccount | null>;
|
|
70
|
+
listLinkedAccounts: () => Promise<LinkedOAuthAccount[]>;
|
|
71
|
+
unlinkOAuth: (provider: string) => Promise<void>;
|
|
72
|
+
signOut: () => Promise<void>;
|
|
73
|
+
error: string | null;
|
|
74
|
+
}
|
|
75
|
+
interface AuthStatus {
|
|
76
|
+
state: AuthState;
|
|
77
|
+
isAuthenticated: boolean;
|
|
78
|
+
isLoading: boolean;
|
|
79
|
+
}
|
|
80
|
+
declare function useAuth(): UseAuthResult;
|
|
81
|
+
declare function useCurrentUser(): vue.ComputedRef<{
|
|
82
|
+
id: string;
|
|
83
|
+
email: string;
|
|
84
|
+
name: string | null;
|
|
85
|
+
} | null>;
|
|
86
|
+
declare function useAuthStatus(): AuthStatus;
|
|
87
|
+
|
|
88
|
+
interface OrgContextValue {
|
|
89
|
+
client: OrgClient;
|
|
90
|
+
session: OrgSession;
|
|
91
|
+
}
|
|
92
|
+
declare const OrgProvider: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
93
|
+
client: {
|
|
94
|
+
type: PropType<OrgClient>;
|
|
95
|
+
required: true;
|
|
96
|
+
};
|
|
97
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
98
|
+
[key: string]: any;
|
|
99
|
+
}>[] | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
100
|
+
client: {
|
|
101
|
+
type: PropType<OrgClient>;
|
|
102
|
+
required: true;
|
|
103
|
+
};
|
|
104
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
105
|
+
declare function useOrgContext(): OrgContextValue;
|
|
106
|
+
|
|
107
|
+
interface UseOrgResult {
|
|
108
|
+
org: ClientOrganization | null;
|
|
109
|
+
role: string | null;
|
|
110
|
+
orgId: string | null;
|
|
111
|
+
switchOrg: (orgId: string) => Promise<void>;
|
|
112
|
+
createOrg: (params: {
|
|
113
|
+
name: string;
|
|
114
|
+
slug?: string;
|
|
115
|
+
}) => Promise<ClientOrganization>;
|
|
116
|
+
leaveOrg: () => Promise<void>;
|
|
117
|
+
clearOrg: () => void;
|
|
118
|
+
listOrgs: () => Promise<ClientOrganization[]>;
|
|
119
|
+
error: string | null;
|
|
120
|
+
}
|
|
121
|
+
interface UseOrgMembersResult {
|
|
122
|
+
members: ClientMembership[];
|
|
123
|
+
isLoading: boolean;
|
|
124
|
+
refresh: () => Promise<void>;
|
|
125
|
+
invite: (email: string, role: string) => Promise<ClientInvitation>;
|
|
126
|
+
removeMember: (userId: string) => Promise<void>;
|
|
127
|
+
updateRole: (userId: string, role: string) => Promise<void>;
|
|
128
|
+
error: string | null;
|
|
129
|
+
}
|
|
130
|
+
declare function useOrg(): UseOrgResult;
|
|
131
|
+
declare function useOrgMembers(orgId: string): UseOrgMembersResult;
|
|
132
|
+
declare function usePermission(requiredRole: string): Readonly<{
|
|
133
|
+
value: boolean;
|
|
134
|
+
}>;
|
|
135
|
+
|
|
136
|
+
export { type AuthContextValue, AuthProvider, type AuthProviderProps, type AuthStatus, type OrgContextValue, OrgProvider, type UseAuthResult, type UseOrgMembersResult, type UseOrgResult, authContextKey, useAuth, useAuthContext, useAuthStatus, useCurrentUser, useOrg, useOrgContext, useOrgMembers, usePermission };
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAuthSession,
|
|
3
|
+
createOrgMembersActions,
|
|
4
|
+
createOrgSession,
|
|
5
|
+
loadOrgMembers
|
|
6
|
+
} from "./chunk-7OXBRSJL.js";
|
|
7
|
+
|
|
8
|
+
// src/vue/auth-provider.ts
|
|
9
|
+
import { defineComponent, h, inject, onScopeDispose, provide, shallowRef } from "vue";
|
|
10
|
+
|
|
11
|
+
// src/vue/auth-context.ts
|
|
12
|
+
var authContextKey = /* @__PURE__ */ Symbol("korajs-auth-context");
|
|
13
|
+
|
|
14
|
+
// src/vue/auth-provider.ts
|
|
15
|
+
var AuthProvider = defineComponent({
|
|
16
|
+
name: "AuthProvider",
|
|
17
|
+
props: {
|
|
18
|
+
client: {
|
|
19
|
+
type: Object,
|
|
20
|
+
required: true
|
|
21
|
+
},
|
|
22
|
+
fallback: {
|
|
23
|
+
type: [Object, String],
|
|
24
|
+
default: null
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
setup(props, { slots }) {
|
|
28
|
+
const session = createAuthSession(props.client);
|
|
29
|
+
const snapshot = shallowRef(session.getSnapshot());
|
|
30
|
+
const unsubscribe = session.subscribe(() => {
|
|
31
|
+
snapshot.value = session.getSnapshot();
|
|
32
|
+
});
|
|
33
|
+
onScopeDispose(() => {
|
|
34
|
+
unsubscribe();
|
|
35
|
+
session.destroy();
|
|
36
|
+
});
|
|
37
|
+
const contextValue = {
|
|
38
|
+
client: props.client,
|
|
39
|
+
get state() {
|
|
40
|
+
return snapshot.value.state;
|
|
41
|
+
},
|
|
42
|
+
get isLoading() {
|
|
43
|
+
return snapshot.value.isLoading;
|
|
44
|
+
},
|
|
45
|
+
session
|
|
46
|
+
};
|
|
47
|
+
provide(authContextKey, contextValue);
|
|
48
|
+
return () => {
|
|
49
|
+
const current = snapshot.value;
|
|
50
|
+
if (current.initError) {
|
|
51
|
+
return h(
|
|
52
|
+
"div",
|
|
53
|
+
{
|
|
54
|
+
style: { color: "red", padding: "1rem", fontFamily: "monospace" },
|
|
55
|
+
role: "alert"
|
|
56
|
+
},
|
|
57
|
+
[h("strong", null, "Kora Auth initialization error: "), current.initError.message]
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
if (current.isLoading && props.fallback !== null) {
|
|
61
|
+
return props.fallback;
|
|
62
|
+
}
|
|
63
|
+
return slots.default?.();
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
function useAuthContext() {
|
|
68
|
+
const context = inject(authContextKey);
|
|
69
|
+
if (!context) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"useAuth must be used within <AuthProvider>. Wrap your app with <AuthProvider client={authClient}>."
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return context;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/vue/use-auth.ts
|
|
78
|
+
import { computed, onScopeDispose as onScopeDispose2, reactive } from "vue";
|
|
79
|
+
function useAuth() {
|
|
80
|
+
const { session } = useAuthContext();
|
|
81
|
+
const state = reactive({ ...session.getSnapshot() });
|
|
82
|
+
const sync = () => {
|
|
83
|
+
Object.assign(state, session.getSnapshot());
|
|
84
|
+
};
|
|
85
|
+
const unsubscribe = session.subscribe(sync);
|
|
86
|
+
sync();
|
|
87
|
+
onScopeDispose2(unsubscribe);
|
|
88
|
+
return {
|
|
89
|
+
get user() {
|
|
90
|
+
return state.user;
|
|
91
|
+
},
|
|
92
|
+
get isAuthenticated() {
|
|
93
|
+
return state.isAuthenticated;
|
|
94
|
+
},
|
|
95
|
+
get isLoading() {
|
|
96
|
+
return state.isLoading;
|
|
97
|
+
},
|
|
98
|
+
get error() {
|
|
99
|
+
return state.error;
|
|
100
|
+
},
|
|
101
|
+
signUp: (params) => session.signUp(params).then(sync),
|
|
102
|
+
signIn: (params) => session.signIn(params).then(sync),
|
|
103
|
+
signInWithOAuth: (provider, options) => session.signInWithOAuth(provider, options).then((result) => {
|
|
104
|
+
sync();
|
|
105
|
+
return result;
|
|
106
|
+
}),
|
|
107
|
+
completeOAuthSignIn: (provider, params) => session.completeOAuthSignIn(provider, params).then(sync),
|
|
108
|
+
getOAuthAuthorizationUrl: (provider, options) => session.getOAuthAuthorizationUrl(provider, options).then((result) => {
|
|
109
|
+
sync();
|
|
110
|
+
return result;
|
|
111
|
+
}),
|
|
112
|
+
linkOAuth: (provider, params) => session.linkOAuth(provider, params).then((result) => {
|
|
113
|
+
sync();
|
|
114
|
+
return result;
|
|
115
|
+
}),
|
|
116
|
+
listLinkedAccounts: () => session.listLinkedAccounts().then((result) => {
|
|
117
|
+
sync();
|
|
118
|
+
return result;
|
|
119
|
+
}),
|
|
120
|
+
unlinkOAuth: (provider) => session.unlinkOAuth(provider).then(sync),
|
|
121
|
+
signOut: () => session.signOut().then(sync)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function useCurrentUser() {
|
|
125
|
+
const { session } = useAuthContext();
|
|
126
|
+
const state = reactive({ user: session.getSnapshot().user });
|
|
127
|
+
const sync = () => {
|
|
128
|
+
state.user = session.getSnapshot().user;
|
|
129
|
+
};
|
|
130
|
+
const unsubscribe = session.subscribe(sync);
|
|
131
|
+
onScopeDispose2(unsubscribe);
|
|
132
|
+
return computed(() => state.user);
|
|
133
|
+
}
|
|
134
|
+
function useAuthStatus() {
|
|
135
|
+
const { session } = useAuthContext();
|
|
136
|
+
const state = reactive({
|
|
137
|
+
state: session.getSnapshot().state,
|
|
138
|
+
isAuthenticated: session.getSnapshot().isAuthenticated,
|
|
139
|
+
isLoading: session.getSnapshot().isLoading
|
|
140
|
+
});
|
|
141
|
+
const sync = () => {
|
|
142
|
+
const snapshot = session.getSnapshot();
|
|
143
|
+
state.state = snapshot.state;
|
|
144
|
+
state.isAuthenticated = snapshot.isAuthenticated;
|
|
145
|
+
state.isLoading = snapshot.isLoading;
|
|
146
|
+
};
|
|
147
|
+
const unsubscribe = session.subscribe(sync);
|
|
148
|
+
sync();
|
|
149
|
+
onScopeDispose2(unsubscribe);
|
|
150
|
+
return state;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/vue/org-provider.ts
|
|
154
|
+
import { defineComponent as defineComponent2, inject as inject2, onScopeDispose as onScopeDispose3, provide as provide2 } from "vue";
|
|
155
|
+
var orgContextKey = /* @__PURE__ */ Symbol("korajs-org-context");
|
|
156
|
+
var OrgProvider = defineComponent2({
|
|
157
|
+
name: "OrgProvider",
|
|
158
|
+
props: {
|
|
159
|
+
client: {
|
|
160
|
+
type: Object,
|
|
161
|
+
required: true
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
setup(props, { slots }) {
|
|
165
|
+
const session = createOrgSession(props.client);
|
|
166
|
+
onScopeDispose3(() => {
|
|
167
|
+
session.destroy();
|
|
168
|
+
});
|
|
169
|
+
const contextValue = {
|
|
170
|
+
client: props.client,
|
|
171
|
+
session
|
|
172
|
+
};
|
|
173
|
+
provide2(orgContextKey, contextValue);
|
|
174
|
+
return () => slots.default?.();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
function useOrgContext() {
|
|
178
|
+
const context = inject2(orgContextKey);
|
|
179
|
+
if (!context) {
|
|
180
|
+
throw new Error(
|
|
181
|
+
'useOrg / useOrgMembers / usePermission must be used within an <OrgProvider>. Wrap your component tree with <OrgProvider :client="orgClient">.'
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
return context;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/vue/org-hooks.ts
|
|
188
|
+
import { onScopeDispose as onScopeDispose4, reactive as reactive2, readonly, ref, watch } from "vue";
|
|
189
|
+
function useOrgSnapshot(session) {
|
|
190
|
+
const state = reactive2({ ...session.getSnapshot() });
|
|
191
|
+
const sync = () => {
|
|
192
|
+
Object.assign(state, session.getSnapshot());
|
|
193
|
+
};
|
|
194
|
+
const unsubscribe = session.subscribe(sync);
|
|
195
|
+
sync();
|
|
196
|
+
onScopeDispose4(unsubscribe);
|
|
197
|
+
return state;
|
|
198
|
+
}
|
|
199
|
+
function useOrg() {
|
|
200
|
+
const { client, session } = useOrgContext();
|
|
201
|
+
const snapshot = useOrgSnapshot(session);
|
|
202
|
+
const error = ref(null);
|
|
203
|
+
const switchOrg = async (orgId) => {
|
|
204
|
+
error.value = null;
|
|
205
|
+
try {
|
|
206
|
+
await client.switchOrg(orgId);
|
|
207
|
+
} catch (err) {
|
|
208
|
+
error.value = err instanceof Error ? err.message : String(err);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
const createOrg = async (params) => {
|
|
212
|
+
error.value = null;
|
|
213
|
+
try {
|
|
214
|
+
return await client.createOrg(params);
|
|
215
|
+
} catch (err) {
|
|
216
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
217
|
+
error.value = message;
|
|
218
|
+
throw err;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const leaveOrg = async () => {
|
|
222
|
+
if (!snapshot.orgId) return;
|
|
223
|
+
error.value = null;
|
|
224
|
+
try {
|
|
225
|
+
await client.leaveOrg(snapshot.orgId);
|
|
226
|
+
} catch (err) {
|
|
227
|
+
error.value = err instanceof Error ? err.message : String(err);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
const clearOrg = () => {
|
|
231
|
+
client.clearActiveOrg();
|
|
232
|
+
};
|
|
233
|
+
const listOrgs = async () => {
|
|
234
|
+
try {
|
|
235
|
+
return await client.listOrgs();
|
|
236
|
+
} catch (err) {
|
|
237
|
+
error.value = err instanceof Error ? err.message : String(err);
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
return {
|
|
242
|
+
get org() {
|
|
243
|
+
return snapshot.org;
|
|
244
|
+
},
|
|
245
|
+
get role() {
|
|
246
|
+
return snapshot.role;
|
|
247
|
+
},
|
|
248
|
+
get orgId() {
|
|
249
|
+
return snapshot.orgId;
|
|
250
|
+
},
|
|
251
|
+
switchOrg,
|
|
252
|
+
createOrg,
|
|
253
|
+
leaveOrg,
|
|
254
|
+
clearOrg,
|
|
255
|
+
listOrgs,
|
|
256
|
+
get error() {
|
|
257
|
+
return error.value;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function useOrgMembers(orgId) {
|
|
262
|
+
const { client } = useOrgContext();
|
|
263
|
+
const members = ref([]);
|
|
264
|
+
const isLoading = ref(true);
|
|
265
|
+
const error = ref(null);
|
|
266
|
+
const refresh = async () => {
|
|
267
|
+
isLoading.value = true;
|
|
268
|
+
error.value = null;
|
|
269
|
+
try {
|
|
270
|
+
members.value = await loadOrgMembers(client, orgId);
|
|
271
|
+
} catch (err) {
|
|
272
|
+
error.value = err instanceof Error ? err.message : String(err);
|
|
273
|
+
} finally {
|
|
274
|
+
isLoading.value = false;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
watch(
|
|
278
|
+
() => orgId,
|
|
279
|
+
() => {
|
|
280
|
+
void refresh();
|
|
281
|
+
},
|
|
282
|
+
{ immediate: true }
|
|
283
|
+
);
|
|
284
|
+
const actions = createOrgMembersActions(client, orgId, (message) => {
|
|
285
|
+
error.value = message;
|
|
286
|
+
});
|
|
287
|
+
const invite = async (email, role) => {
|
|
288
|
+
const result = await actions.invite(email, role);
|
|
289
|
+
await refresh();
|
|
290
|
+
return result;
|
|
291
|
+
};
|
|
292
|
+
const removeMember = async (userId) => {
|
|
293
|
+
await actions.removeMember(userId);
|
|
294
|
+
await refresh();
|
|
295
|
+
};
|
|
296
|
+
const updateRole = async (userId, role) => {
|
|
297
|
+
await actions.updateRole(userId, role);
|
|
298
|
+
await refresh();
|
|
299
|
+
};
|
|
300
|
+
return {
|
|
301
|
+
get members() {
|
|
302
|
+
return members.value;
|
|
303
|
+
},
|
|
304
|
+
get isLoading() {
|
|
305
|
+
return isLoading.value;
|
|
306
|
+
},
|
|
307
|
+
refresh,
|
|
308
|
+
invite,
|
|
309
|
+
removeMember,
|
|
310
|
+
updateRole,
|
|
311
|
+
get error() {
|
|
312
|
+
return error.value;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function usePermission(requiredRole) {
|
|
317
|
+
const { session } = useOrgContext();
|
|
318
|
+
const allowed = ref(session.checkPermission(requiredRole));
|
|
319
|
+
const unsubscribe = session.subscribe(() => {
|
|
320
|
+
allowed.value = session.checkPermission(requiredRole);
|
|
321
|
+
});
|
|
322
|
+
onScopeDispose4(unsubscribe);
|
|
323
|
+
return readonly(allowed);
|
|
324
|
+
}
|
|
325
|
+
export {
|
|
326
|
+
AuthProvider,
|
|
327
|
+
OrgProvider,
|
|
328
|
+
authContextKey,
|
|
329
|
+
useAuth,
|
|
330
|
+
useAuthContext,
|
|
331
|
+
useAuthStatus,
|
|
332
|
+
useCurrentUser,
|
|
333
|
+
useOrg,
|
|
334
|
+
useOrgContext,
|
|
335
|
+
useOrgMembers,
|
|
336
|
+
usePermission
|
|
337
|
+
};
|
|
338
|
+
//# sourceMappingURL=vue.js.map
|
package/dist/vue.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vue/auth-provider.ts","../src/vue/auth-context.ts","../src/vue/use-auth.ts","../src/vue/org-provider.ts","../src/vue/org-hooks.ts"],"sourcesContent":["import type { PropType, VNode } from 'vue'\nimport { defineComponent, h, inject, onScopeDispose, provide, shallowRef } from 'vue'\nimport type { AuthClient } from '../client/auth-client'\nimport { createAuthSession, type AuthSessionSnapshot } from '../bindings/create-auth-session'\nimport { authContextKey, type AuthContextValue } from './auth-context'\n\nexport const AuthProvider = defineComponent({\n\tname: 'AuthProvider',\n\tprops: {\n\t\tclient: {\n\t\t\ttype: Object as PropType<AuthClient>,\n\t\t\trequired: true,\n\t\t},\n\t\tfallback: {\n\t\t\ttype: [Object, String] as PropType<VNode | string | null>,\n\t\t\tdefault: null,\n\t\t},\n\t},\n\tsetup(props, { slots }) {\n\t\tconst session = createAuthSession(props.client)\n\t\tconst snapshot = shallowRef<AuthSessionSnapshot>(session.getSnapshot())\n\n\t\tconst unsubscribe = session.subscribe(() => {\n\t\t\tsnapshot.value = session.getSnapshot()\n\t\t})\n\n\t\tonScopeDispose(() => {\n\t\t\tunsubscribe()\n\t\t\tsession.destroy()\n\t\t})\n\n\t\tconst contextValue: AuthContextValue = {\n\t\t\tclient: props.client,\n\t\t\tget state() {\n\t\t\t\treturn snapshot.value.state\n\t\t\t},\n\t\t\tget isLoading() {\n\t\t\t\treturn snapshot.value.isLoading\n\t\t\t},\n\t\t\tsession,\n\t\t}\n\n\t\tprovide(authContextKey, contextValue)\n\n\t\treturn () => {\n\t\t\tconst current = snapshot.value\n\n\t\t\tif (current.initError) {\n\t\t\t\treturn h(\n\t\t\t\t\t'div',\n\t\t\t\t\t{\n\t\t\t\t\t\tstyle: { color: 'red', padding: '1rem', fontFamily: 'monospace' },\n\t\t\t\t\t\trole: 'alert',\n\t\t\t\t\t},\n\t\t\t\t\t[h('strong', null, 'Kora Auth initialization error: '), current.initError.message],\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tif (current.isLoading && props.fallback !== null) {\n\t\t\t\treturn props.fallback\n\t\t\t}\n\n\t\t\treturn slots.default?.()\n\t\t}\n\t},\n})\n\nexport function useAuthContext(): AuthContextValue {\n\tconst context = inject<AuthContextValue | undefined>(authContextKey)\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t'useAuth must be used within <AuthProvider>. Wrap your app with <AuthProvider client={authClient}>.',\n\t\t)\n\t}\n\treturn context\n}\n","import type { AuthClient, AuthState } from '../client/auth-client'\n\nexport interface AuthContextValue {\n\tclient: AuthClient\n\tstate: AuthState\n\tisLoading: boolean\n\tsession: import('../bindings/create-auth-session').AuthSession\n}\n\nexport const authContextKey = Symbol('korajs-auth-context')\n","import { computed, onScopeDispose, reactive } from 'vue'\nimport type {\n\tAuthUser,\n\tLinkedOAuthAccount,\n\tOAuthAuthorizationOptions,\n\tOAuthAuthorizationResult,\n\tOAuthCallbackParams,\n} from '../client/auth-client'\nimport { useAuthContext } from './auth-provider'\n\nexport interface UseAuthResult {\n\tuser: AuthUser | null\n\tisAuthenticated: boolean\n\tisLoading: boolean\n\tsignUp: (params: {\n\t\temail: string\n\t\tpassword: string\n\t\tname?: string\n\t\tdeviceId?: string\n\t\tdevicePublicKey?: string\n\t}) => Promise<void>\n\tsignIn: (params: {\n\t\temail: string\n\t\tpassword: string\n\t\tdeviceId?: string\n\t\tdevicePublicKey?: string\n\t}) => Promise<void>\n\tsignInWithOAuth: (\n\t\tprovider: string,\n\t\toptions?: OAuthAuthorizationOptions,\n\t) => Promise<OAuthAuthorizationResult>\n\tcompleteOAuthSignIn: (provider: string, params: OAuthCallbackParams) => Promise<void>\n\tgetOAuthAuthorizationUrl: (\n\t\tprovider: string,\n\t\toptions?: OAuthAuthorizationOptions,\n\t) => Promise<OAuthAuthorizationResult>\n\tlinkOAuth: (provider: string, params: OAuthCallbackParams) => Promise<LinkedOAuthAccount | null>\n\tlistLinkedAccounts: () => Promise<LinkedOAuthAccount[]>\n\tunlinkOAuth: (provider: string) => Promise<void>\n\tsignOut: () => Promise<void>\n\terror: string | null\n}\n\nexport interface AuthStatus {\n\tstate: import('../client/auth-client').AuthState\n\tisAuthenticated: boolean\n\tisLoading: boolean\n}\n\nexport function useAuth(): UseAuthResult {\n\tconst { session } = useAuthContext()\n\tconst state = reactive({ ...session.getSnapshot() })\n\n\tconst sync = (): void => {\n\t\tObject.assign(state, session.getSnapshot())\n\t}\n\n\tconst unsubscribe = session.subscribe(sync)\n\tsync()\n\n\tonScopeDispose(unsubscribe)\n\n\treturn {\n\t\tget user() {\n\t\t\treturn state.user\n\t\t},\n\t\tget isAuthenticated() {\n\t\t\treturn state.isAuthenticated\n\t\t},\n\t\tget isLoading() {\n\t\t\treturn state.isLoading\n\t\t},\n\t\tget error() {\n\t\t\treturn state.error\n\t\t},\n\t\tsignUp: (params) => session.signUp(params).then(sync),\n\t\tsignIn: (params) => session.signIn(params).then(sync),\n\t\tsignInWithOAuth: (provider, options) => session.signInWithOAuth(provider, options).then((result) => {\n\t\t\tsync()\n\t\t\treturn result\n\t\t}),\n\t\tcompleteOAuthSignIn: (provider, params) =>\n\t\t\tsession.completeOAuthSignIn(provider, params).then(sync),\n\t\tgetOAuthAuthorizationUrl: (provider, options) =>\n\t\t\tsession.getOAuthAuthorizationUrl(provider, options).then((result) => {\n\t\t\t\tsync()\n\t\t\t\treturn result\n\t\t\t}),\n\t\tlinkOAuth: (provider, params) => session.linkOAuth(provider, params).then((result) => {\n\t\t\tsync()\n\t\t\treturn result\n\t\t}),\n\t\tlistLinkedAccounts: () =>\n\t\t\tsession.listLinkedAccounts().then((result) => {\n\t\t\t\tsync()\n\t\t\t\treturn result\n\t\t\t}),\n\t\tunlinkOAuth: (provider) => session.unlinkOAuth(provider).then(sync),\n\t\tsignOut: () => session.signOut().then(sync),\n\t}\n}\n\nexport function useCurrentUser() {\n\tconst { session } = useAuthContext()\n\tconst state = reactive({ user: session.getSnapshot().user })\n\n\tconst sync = (): void => {\n\t\tstate.user = session.getSnapshot().user\n\t}\n\n\tconst unsubscribe = session.subscribe(sync)\n\tonScopeDispose(unsubscribe)\n\n\treturn computed(() => state.user)\n}\n\nexport function useAuthStatus(): AuthStatus {\n\tconst { session } = useAuthContext()\n\tconst state = reactive({\n\t\tstate: session.getSnapshot().state,\n\t\tisAuthenticated: session.getSnapshot().isAuthenticated,\n\t\tisLoading: session.getSnapshot().isLoading,\n\t})\n\n\tconst sync = (): void => {\n\t\tconst snapshot = session.getSnapshot()\n\t\tstate.state = snapshot.state\n\t\tstate.isAuthenticated = snapshot.isAuthenticated\n\t\tstate.isLoading = snapshot.isLoading\n\t}\n\n\tconst unsubscribe = session.subscribe(sync)\n\tsync()\n\tonScopeDispose(unsubscribe)\n\n\treturn state\n}\n","import type { InjectionKey } from 'vue'\nimport type { PropType } from 'vue'\nimport { defineComponent, inject, onScopeDispose, provide } from 'vue'\nimport type { OrgClient } from '../client/org-client'\nimport { createOrgSession, type OrgSession } from '../bindings/create-org-session'\n\nexport interface OrgContextValue {\n\tclient: OrgClient\n\tsession: OrgSession\n}\n\nexport const orgContextKey: InjectionKey<OrgContextValue> = Symbol('korajs-org-context')\n\nexport const OrgProvider = defineComponent({\n\tname: 'OrgProvider',\n\tprops: {\n\t\tclient: {\n\t\t\ttype: Object as PropType<OrgClient>,\n\t\t\trequired: true,\n\t\t},\n\t},\n\tsetup(props, { slots }) {\n\t\tconst session = createOrgSession(props.client)\n\n\t\tonScopeDispose(() => {\n\t\t\tsession.destroy()\n\t\t})\n\n\t\tconst contextValue: OrgContextValue = {\n\t\t\tclient: props.client,\n\t\t\tsession,\n\t\t}\n\n\t\tprovide(orgContextKey, contextValue)\n\n\t\treturn () => slots.default?.()\n\t},\n})\n\nexport function useOrgContext(): OrgContextValue {\n\tconst context = inject(orgContextKey)\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t'useOrg / useOrgMembers / usePermission must be used within an <OrgProvider>. ' +\n\t\t\t\t'Wrap your component tree with <OrgProvider :client=\"orgClient\">.',\n\t\t)\n\t}\n\treturn context\n}\n","import { onScopeDispose, reactive, readonly, ref, watch } from 'vue'\nimport type {\n\tClientInvitation,\n\tClientMembership,\n\tClientOrganization,\n} from '../client/org-client'\nimport {\n\tcreateOrgMembersActions,\n\tloadOrgMembers,\n\ttype OrgSnapshot,\n} from '../bindings/create-org-session'\nimport { useOrgContext } from './org-provider'\n\nexport interface UseOrgResult {\n\torg: ClientOrganization | null\n\trole: string | null\n\torgId: string | null\n\tswitchOrg: (orgId: string) => Promise<void>\n\tcreateOrg: (params: { name: string; slug?: string }) => Promise<ClientOrganization>\n\tleaveOrg: () => Promise<void>\n\tclearOrg: () => void\n\tlistOrgs: () => Promise<ClientOrganization[]>\n\terror: string | null\n}\n\nexport interface UseOrgMembersResult {\n\tmembers: ClientMembership[]\n\tisLoading: boolean\n\trefresh: () => Promise<void>\n\tinvite: (email: string, role: string) => Promise<ClientInvitation>\n\tremoveMember: (userId: string) => Promise<void>\n\tupdateRole: (userId: string, role: string) => Promise<void>\n\terror: string | null\n}\n\nfunction useOrgSnapshot(session: ReturnType<typeof useOrgContext>['session']): OrgSnapshot {\n\tconst state = reactive({ ...session.getSnapshot() })\n\n\tconst sync = (): void => {\n\t\tObject.assign(state, session.getSnapshot())\n\t}\n\n\tconst unsubscribe = session.subscribe(sync)\n\tsync()\n\n\tonScopeDispose(unsubscribe)\n\n\treturn state\n}\n\nexport function useOrg(): UseOrgResult {\n\tconst { client, session } = useOrgContext()\n\tconst snapshot = useOrgSnapshot(session)\n\tconst error = ref<string | null>(null)\n\n\tconst switchOrg = async (orgId: string): Promise<void> => {\n\t\terror.value = null\n\t\ttry {\n\t\t\tawait client.switchOrg(orgId)\n\t\t} catch (err) {\n\t\t\terror.value = err instanceof Error ? err.message : String(err)\n\t\t}\n\t}\n\n\tconst createOrg = async (params: {\n\t\tname: string\n\t\tslug?: string\n\t}): Promise<ClientOrganization> => {\n\t\terror.value = null\n\t\ttry {\n\t\t\treturn await client.createOrg(params)\n\t\t} catch (err) {\n\t\t\tconst message = err instanceof Error ? err.message : String(err)\n\t\t\terror.value = message\n\t\t\tthrow err\n\t\t}\n\t}\n\n\tconst leaveOrg = async (): Promise<void> => {\n\t\tif (!snapshot.orgId) return\n\t\terror.value = null\n\t\ttry {\n\t\t\tawait client.leaveOrg(snapshot.orgId)\n\t\t} catch (err) {\n\t\t\terror.value = err instanceof Error ? err.message : String(err)\n\t\t}\n\t}\n\n\tconst clearOrg = (): void => {\n\t\tclient.clearActiveOrg()\n\t}\n\n\tconst listOrgs = async (): Promise<ClientOrganization[]> => {\n\t\ttry {\n\t\t\treturn await client.listOrgs()\n\t\t} catch (err) {\n\t\t\terror.value = err instanceof Error ? err.message : String(err)\n\t\t\treturn []\n\t\t}\n\t}\n\n\treturn {\n\t\tget org() {\n\t\t\treturn snapshot.org\n\t\t},\n\t\tget role() {\n\t\t\treturn snapshot.role\n\t\t},\n\t\tget orgId() {\n\t\t\treturn snapshot.orgId\n\t\t},\n\t\tswitchOrg,\n\t\tcreateOrg,\n\t\tleaveOrg,\n\t\tclearOrg,\n\t\tlistOrgs,\n\t\tget error() {\n\t\t\treturn error.value\n\t\t},\n\t}\n}\n\nexport function useOrgMembers(orgId: string): UseOrgMembersResult {\n\tconst { client } = useOrgContext()\n\tconst members = ref<ClientMembership[]>([])\n\tconst isLoading = ref(true)\n\tconst error = ref<string | null>(null)\n\n\tconst refresh = async (): Promise<void> => {\n\t\tisLoading.value = true\n\t\terror.value = null\n\t\ttry {\n\t\t\tmembers.value = await loadOrgMembers(client, orgId)\n\t\t} catch (err) {\n\t\t\terror.value = err instanceof Error ? err.message : String(err)\n\t\t} finally {\n\t\t\tisLoading.value = false\n\t\t}\n\t}\n\n\twatch(\n\t\t() => orgId,\n\t\t() => {\n\t\t\tvoid refresh()\n\t\t},\n\t\t{ immediate: true },\n\t)\n\n\tconst actions = createOrgMembersActions(client, orgId, (message) => {\n\t\terror.value = message\n\t})\n\n\tconst invite = async (email: string, role: string): Promise<ClientInvitation> => {\n\t\tconst result = await actions.invite(email, role)\n\t\tawait refresh()\n\t\treturn result\n\t}\n\n\tconst removeMember = async (userId: string): Promise<void> => {\n\t\tawait actions.removeMember(userId)\n\t\tawait refresh()\n\t}\n\n\tconst updateRole = async (userId: string, role: string): Promise<void> => {\n\t\tawait actions.updateRole(userId, role)\n\t\tawait refresh()\n\t}\n\n\treturn {\n\t\tget members() {\n\t\t\treturn members.value\n\t\t},\n\t\tget isLoading() {\n\t\t\treturn isLoading.value\n\t\t},\n\t\trefresh,\n\t\tinvite,\n\t\tremoveMember,\n\t\tupdateRole,\n\t\tget error() {\n\t\t\treturn error.value\n\t\t},\n\t}\n}\n\nexport function usePermission(requiredRole: string): Readonly<{ value: boolean }> {\n\tconst { session } = useOrgContext()\n\tconst allowed = ref(session.checkPermission(requiredRole))\n\n\tconst unsubscribe = session.subscribe(() => {\n\t\tallowed.value = session.checkPermission(requiredRole)\n\t})\n\n\tonScopeDispose(unsubscribe)\n\n\treturn readonly(allowed)\n}\n"],"mappings":";;;;;;;;AACA,SAAS,iBAAiB,GAAG,QAAQ,gBAAgB,SAAS,kBAAkB;;;ACQzE,IAAM,iBAAiB,uBAAO,qBAAqB;;;ADHnD,IAAM,eAAe,gBAAgB;AAAA,EAC3C,MAAM;AAAA,EACN,OAAO;AAAA,IACN,QAAQ;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,UAAU;AAAA,MACT,MAAM,CAAC,QAAQ,MAAM;AAAA,M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Y;AACnE,UAAM,QAAQ;AAAA,EACf,CAAC;AAED,QAAM,SAAS,OAAO,OAAe,SAA4C;AAChF,UAAM,SAAS,MAAM,QAAQ,OAAO,OAAO,IAAI;AAC/C,UAAM,QAAQ;AACd,WAAO;AAAA,EACR;AAEA,QAAM,eAAe,OAAO,WAAkC;AAC7D,UAAM,QAAQ,aAAa,MAAM;AACjC,UAAM,QAAQ;AAAA,EACf;AAEA,QAAM,aAAa,OAAO,QAAgB,SAAgC;AACzE,UAAM,QAAQ,WAAW,QAAQ,IAAI;AACrC,UAAM,QAAQ;AAAA,EACf;AAEA,SAAO;AAAA,IACN,IAAI,UAAU;AACb,aAAO,QAAQ;AAAA,IAChB;AAAA,IACA,IAAI,YAAY;AACf,aAAO,UAAU;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,IAAI,QAAQ;AACX,aAAO,MAAM;AAAA,IACd;AAAA,EACD;AACD;AAEO,SAAS,cAAc,cAAoD;AACjF,QAAM,EAAE,QAAQ,IAAI,cAAc;AAClC,QAAM,UAAU,IAAI,QAAQ,gBAAgB,YAAY,CAAC;AAEzD,QAAM,cAAc,QAAQ,UAAU,MAAM;AAC3C,YAAQ,QAAQ,QAAQ,gBAAgB,YAAY;AAAA,EACrD,CAAC;AAED,EAAAA,gBAAe,WAAW;AAE1B,SAAO,SAAS,OAAO;AACxB;","names":["onScopeDispose","onScopeDispose","defineComponent","inject","onScopeDispose","provide","defineComponent","onScopeDispose","provide","inject","onScopeDispose","reactive","reactive","onScopeDispose"]}
|