@authsome/ui-vue 1.0.0 → 1.1.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/dist/index.d.ts +21 -13
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ declare function useAuth(): {
|
|
|
25
25
|
} | {
|
|
26
26
|
readonly status: "authenticated";
|
|
27
27
|
readonly user: {
|
|
28
|
-
readonly app_id:
|
|
28
|
+
readonly app_id: string;
|
|
29
29
|
readonly ban_expires?: string | undefined;
|
|
30
30
|
readonly ban_reason?: string | undefined;
|
|
31
31
|
readonly banned: boolean;
|
|
@@ -34,12 +34,15 @@ declare function useAuth(): {
|
|
|
34
34
|
readonly display_username?: string | undefined;
|
|
35
35
|
readonly email: string;
|
|
36
36
|
readonly email_verified: boolean;
|
|
37
|
-
readonly
|
|
37
|
+
readonly env_id: string;
|
|
38
|
+
readonly first_name: string;
|
|
39
|
+
readonly id: string;
|
|
38
40
|
readonly image?: string | undefined;
|
|
41
|
+
readonly last_name: string;
|
|
39
42
|
readonly metadata?: {
|
|
40
43
|
readonly [x: string]: Readonly<unknown>;
|
|
41
44
|
} | undefined;
|
|
42
|
-
readonly
|
|
45
|
+
readonly password_changed_at?: string | undefined;
|
|
43
46
|
readonly phone?: string | undefined;
|
|
44
47
|
readonly phone_verified: boolean;
|
|
45
48
|
readonly updated_at: string;
|
|
@@ -69,7 +72,7 @@ declare function useAuth(): {
|
|
|
69
72
|
} | {
|
|
70
73
|
readonly status: "authenticated";
|
|
71
74
|
readonly user: {
|
|
72
|
-
readonly app_id:
|
|
75
|
+
readonly app_id: string;
|
|
73
76
|
readonly ban_expires?: string | undefined;
|
|
74
77
|
readonly ban_reason?: string | undefined;
|
|
75
78
|
readonly banned: boolean;
|
|
@@ -78,12 +81,15 @@ declare function useAuth(): {
|
|
|
78
81
|
readonly display_username?: string | undefined;
|
|
79
82
|
readonly email: string;
|
|
80
83
|
readonly email_verified: boolean;
|
|
81
|
-
readonly
|
|
84
|
+
readonly env_id: string;
|
|
85
|
+
readonly first_name: string;
|
|
86
|
+
readonly id: string;
|
|
82
87
|
readonly image?: string | undefined;
|
|
88
|
+
readonly last_name: string;
|
|
83
89
|
readonly metadata?: {
|
|
84
90
|
readonly [x: string]: Readonly<unknown>;
|
|
85
91
|
} | undefined;
|
|
86
|
-
readonly
|
|
92
|
+
readonly password_changed_at?: string | undefined;
|
|
87
93
|
readonly phone?: string | undefined;
|
|
88
94
|
readonly phone_verified: boolean;
|
|
89
95
|
readonly updated_at: string;
|
|
@@ -114,7 +120,7 @@ declare function useAuth(): {
|
|
|
114
120
|
error: vue.ComputedRef<string | null>;
|
|
115
121
|
client: AuthClient;
|
|
116
122
|
signIn: (email: string, password: string) => Promise<void>;
|
|
117
|
-
signUp: (email: string, password: string,
|
|
123
|
+
signUp: (email: string, password: string, fields?: Record<string, string>) => Promise<void>;
|
|
118
124
|
signOut: () => Promise<void>;
|
|
119
125
|
submitMFACode: (enrollmentId: string, code: string) => Promise<void>;
|
|
120
126
|
submitRecoveryCode: (code: string) => Promise<void>;
|
|
@@ -132,10 +138,11 @@ declare function useUser(): {
|
|
|
132
138
|
*/
|
|
133
139
|
declare function useOrganizations(): {
|
|
134
140
|
organizations: Readonly<Ref<readonly {
|
|
135
|
-
readonly app_id:
|
|
141
|
+
readonly app_id: string;
|
|
136
142
|
readonly created_at: string;
|
|
137
|
-
readonly created_by:
|
|
138
|
-
readonly
|
|
143
|
+
readonly created_by: string;
|
|
144
|
+
readonly env_id: string;
|
|
145
|
+
readonly id: string;
|
|
139
146
|
readonly logo?: string | undefined;
|
|
140
147
|
readonly metadata?: {
|
|
141
148
|
readonly [x: string]: Readonly<unknown>;
|
|
@@ -144,10 +151,11 @@ declare function useOrganizations(): {
|
|
|
144
151
|
readonly slug: string;
|
|
145
152
|
readonly updated_at: string;
|
|
146
153
|
}[], readonly {
|
|
147
|
-
readonly app_id:
|
|
154
|
+
readonly app_id: string;
|
|
148
155
|
readonly created_at: string;
|
|
149
|
-
readonly created_by:
|
|
150
|
-
readonly
|
|
156
|
+
readonly created_by: string;
|
|
157
|
+
readonly env_id: string;
|
|
158
|
+
readonly id: string;
|
|
151
159
|
readonly logo?: string | undefined;
|
|
152
160
|
readonly metadata?: {
|
|
153
161
|
readonly [x: string]: Readonly<unknown>;
|
package/dist/index.js
CHANGED
|
@@ -56,8 +56,10 @@ function useAuth() {
|
|
|
56
56
|
async function signIn(email, password) {
|
|
57
57
|
await manager.signIn({ email, password });
|
|
58
58
|
}
|
|
59
|
-
async function signUp(email, password,
|
|
60
|
-
|
|
59
|
+
async function signUp(email, password, fields) {
|
|
60
|
+
const { first_name, last_name, username, ...rest } = fields ?? {};
|
|
61
|
+
const metadata = Object.keys(rest).length > 0 ? rest : void 0;
|
|
62
|
+
await manager.signUp({ email, password, first_name, last_name, username, metadata });
|
|
61
63
|
}
|
|
62
64
|
async function signOut() {
|
|
63
65
|
await manager.signOut();
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/composables.ts"],"sourcesContent":["/**\n * Vue 3 composables for AuthSome authentication.\n *\n * Usage:\n * ```ts\n * // main.ts\n * import { createAuthPlugin } from \"@authsome/ui-vue\";\n * app.use(createAuthPlugin({ baseURL: \"https://api.example.com\" }));\n *\n * // Component.vue\n * import { useAuth, useUser } from \"@authsome/ui-vue\";\n * const { signIn, isAuthenticated, user } = useAuth();\n * ```\n */\n\nimport {\n computed,\n inject,\n onMounted,\n onUnmounted,\n readonly,\n ref,\n type App,\n type InjectionKey,\n type Ref,\n} from \"vue\";\nimport {\n AuthManager,\n type AuthConfig,\n type AuthState,\n type AuthClient,\n type User,\n type Session,\n type Organization,\n type ListResponse,\n} from \"@authsome/ui-core\";\n\n/** Injection key for the AuthManager. */\nconst AUTH_KEY: InjectionKey<AuthManager> = Symbol(\"authsome\");\n\n/** Injection key for the reactive auth state. */\nconst AUTH_STATE_KEY: InjectionKey<Ref<AuthState>> = Symbol(\"authsome:state\");\n\n/**\n * Creates a Vue plugin that provides AuthSome authentication.\n *\n * ```ts\n * const app = createApp(App);\n * app.use(createAuthPlugin({ baseURL: \"https://api.example.com\" }));\n * ```\n */\nexport function createAuthPlugin(config: AuthConfig) {\n return {\n install(app: App) {\n const manager = new AuthManager(config);\n const state = ref<AuthState>(manager.getState());\n\n manager.subscribe((s) => {\n state.value = s;\n });\n\n app.provide(AUTH_KEY, manager);\n app.provide(AUTH_STATE_KEY, state);\n\n // Initialize on mount (hydrate from storage).\n void manager.initialize();\n },\n };\n}\n\nfunction useManager(): AuthManager {\n const manager = inject(AUTH_KEY);\n if (!manager) {\n throw new Error(\"useAuth requires the authsome plugin. Call app.use(createAuthPlugin(...)).\");\n }\n return manager;\n}\n\nfunction useAuthState(): Ref<AuthState> {\n const state = inject(AUTH_STATE_KEY);\n if (!state) {\n throw new Error(\"useAuth requires the authsome plugin. Call app.use(createAuthPlugin(...)).\");\n }\n return state;\n}\n\n/**\n * Main auth composable providing state and actions.\n */\nexport function useAuth() {\n const manager = useManager();\n const state = useAuthState();\n\n const isAuthenticated = computed(() => state.value.status === \"authenticated\");\n const isLoading = computed(() => state.value.status === \"loading\");\n\n const user = computed<User | null>(() =>\n state.value.status === \"authenticated\" ? state.value.user : null,\n );\n\n const session = computed<Session | null>(() =>\n state.value.status === \"authenticated\" ? state.value.session : null,\n );\n\n const error = computed<string | null>(() =>\n state.value.status === \"error\" ? state.value.error : null,\n );\n\n async function signIn(email: string, password: string) {\n await manager.signIn({ email, password });\n }\n\n async function signUp(email: string, password: string,
|
|
1
|
+
{"version":3,"sources":["../src/composables.ts"],"sourcesContent":["/**\n * Vue 3 composables for AuthSome authentication.\n *\n * Usage:\n * ```ts\n * // main.ts\n * import { createAuthPlugin } from \"@authsome/ui-vue\";\n * app.use(createAuthPlugin({ baseURL: \"https://api.example.com\" }));\n *\n * // Component.vue\n * import { useAuth, useUser } from \"@authsome/ui-vue\";\n * const { signIn, isAuthenticated, user } = useAuth();\n * ```\n */\n\nimport {\n computed,\n inject,\n onMounted,\n onUnmounted,\n readonly,\n ref,\n type App,\n type InjectionKey,\n type Ref,\n} from \"vue\";\nimport {\n AuthManager,\n type AuthConfig,\n type AuthState,\n type AuthClient,\n type User,\n type Session,\n type Organization,\n type ListResponse,\n} from \"@authsome/ui-core\";\n\n/** Injection key for the AuthManager. */\nconst AUTH_KEY: InjectionKey<AuthManager> = Symbol(\"authsome\");\n\n/** Injection key for the reactive auth state. */\nconst AUTH_STATE_KEY: InjectionKey<Ref<AuthState>> = Symbol(\"authsome:state\");\n\n/**\n * Creates a Vue plugin that provides AuthSome authentication.\n *\n * ```ts\n * const app = createApp(App);\n * app.use(createAuthPlugin({ baseURL: \"https://api.example.com\" }));\n * ```\n */\nexport function createAuthPlugin(config: AuthConfig) {\n return {\n install(app: App) {\n const manager = new AuthManager(config);\n const state = ref<AuthState>(manager.getState());\n\n manager.subscribe((s) => {\n state.value = s;\n });\n\n app.provide(AUTH_KEY, manager);\n app.provide(AUTH_STATE_KEY, state);\n\n // Initialize on mount (hydrate from storage).\n void manager.initialize();\n },\n };\n}\n\nfunction useManager(): AuthManager {\n const manager = inject(AUTH_KEY);\n if (!manager) {\n throw new Error(\"useAuth requires the authsome plugin. Call app.use(createAuthPlugin(...)).\");\n }\n return manager;\n}\n\nfunction useAuthState(): Ref<AuthState> {\n const state = inject(AUTH_STATE_KEY);\n if (!state) {\n throw new Error(\"useAuth requires the authsome plugin. Call app.use(createAuthPlugin(...)).\");\n }\n return state;\n}\n\n/**\n * Main auth composable providing state and actions.\n */\nexport function useAuth() {\n const manager = useManager();\n const state = useAuthState();\n\n const isAuthenticated = computed(() => state.value.status === \"authenticated\");\n const isLoading = computed(() => state.value.status === \"loading\");\n\n const user = computed<User | null>(() =>\n state.value.status === \"authenticated\" ? state.value.user : null,\n );\n\n const session = computed<Session | null>(() =>\n state.value.status === \"authenticated\" ? state.value.session : null,\n );\n\n const error = computed<string | null>(() =>\n state.value.status === \"error\" ? state.value.error : null,\n );\n\n async function signIn(email: string, password: string) {\n await manager.signIn({ email, password });\n }\n\n async function signUp(email: string, password: string, fields?: Record<string, string>) {\n const { first_name, last_name, username, ...rest } = fields ?? {};\n const metadata = Object.keys(rest).length > 0 ? rest : undefined;\n await manager.signUp({ email, password, first_name, last_name, username, metadata });\n }\n\n async function signOut() {\n await manager.signOut();\n }\n\n async function submitMFACode(enrollmentId: string, code: string) {\n await manager.submitMFACode(enrollmentId, code);\n }\n\n async function submitRecoveryCode(code: string) {\n await manager.submitRecoveryCode(code);\n }\n\n return {\n state: readonly(state),\n isAuthenticated,\n isLoading,\n user,\n session,\n error,\n client: manager.getClient(),\n signIn,\n signUp,\n signOut,\n submitMFACode,\n submitRecoveryCode,\n };\n}\n\n/**\n * Composable to fetch and reload the user profile.\n */\nexport function useUser() {\n const { user: authUser, isLoading, session } = useAuth();\n const manager = useManager();\n const localUser = ref<User | null>(authUser.value);\n\n // Keep in sync with auth state.\n const stopWatch = computed(() => authUser.value);\n\n async function reload() {\n if (!session.value) return;\n const u = await manager.getClient().getMe(session.value.session_token);\n localUser.value = u;\n }\n\n return {\n user: computed(() => localUser.value ?? authUser.value),\n isLoading,\n reload,\n };\n}\n\n/**\n * Composable to list organizations.\n */\nexport function useOrganizations() {\n const { session, isAuthenticated } = useAuth();\n const manager = useManager();\n\n const organizations = ref<Organization[]>([]);\n const total = ref(0);\n const isLoading = ref(false);\n\n async function load() {\n if (!session.value) return;\n isLoading.value = true;\n try {\n const res = await manager\n .getClient()\n .listOrganizations(session.value.session_token) as unknown as ListResponse<Organization>;\n organizations.value = res.items;\n total.value = res.total;\n } finally {\n isLoading.value = false;\n }\n }\n\n onMounted(() => {\n if (isAuthenticated.value) {\n void load();\n }\n });\n\n return {\n organizations: readonly(organizations),\n total: readonly(total),\n isLoading: readonly(isLoading),\n reload: load,\n };\n}\n\n/**\n * Composable that returns the current session token.\n */\nexport function useSessionToken() {\n const { session } = useAuth();\n return computed(() => session.value?.session_token ?? null);\n}\n"],"mappings":";AAeA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,OAQK;AAGP,IAAM,WAAsC,uBAAO,UAAU;AAG7D,IAAM,iBAA+C,uBAAO,gBAAgB;AAUrE,SAAS,iBAAiB,QAAoB;AACnD,SAAO;AAAA,IACL,QAAQ,KAAU;AAChB,YAAM,UAAU,IAAI,YAAY,MAAM;AACtC,YAAM,QAAQ,IAAe,QAAQ,SAAS,CAAC;AAE/C,cAAQ,UAAU,CAAC,MAAM;AACvB,cAAM,QAAQ;AAAA,MAChB,CAAC;AAED,UAAI,QAAQ,UAAU,OAAO;AAC7B,UAAI,QAAQ,gBAAgB,KAAK;AAGjC,WAAK,QAAQ,WAAW;AAAA,IAC1B;AAAA,EACF;AACF;AAEA,SAAS,aAA0B;AACjC,QAAM,UAAU,OAAO,QAAQ;AAC/B,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,4EAA4E;AAAA,EAC9F;AACA,SAAO;AACT;AAEA,SAAS,eAA+B;AACtC,QAAM,QAAQ,OAAO,cAAc;AACnC,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,4EAA4E;AAAA,EAC9F;AACA,SAAO;AACT;AAKO,SAAS,UAAU;AACxB,QAAM,UAAU,WAAW;AAC3B,QAAM,QAAQ,aAAa;AAE3B,QAAM,kBAAkB,SAAS,MAAM,MAAM,MAAM,WAAW,eAAe;AAC7E,QAAM,YAAY,SAAS,MAAM,MAAM,MAAM,WAAW,SAAS;AAEjE,QAAM,OAAO;AAAA,IAAsB,MACjC,MAAM,MAAM,WAAW,kBAAkB,MAAM,MAAM,OAAO;AAAA,EAC9D;AAEA,QAAM,UAAU;AAAA,IAAyB,MACvC,MAAM,MAAM,WAAW,kBAAkB,MAAM,MAAM,UAAU;AAAA,EACjE;AAE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AAS,SAAS,KAAK;AAAA,IACtD;AAAA,IACA;AAAA,EACF;AACF;AAKO,SAAS,mBAAmB;AACjC,QAAM,EAAE,SAAS,gBAAgB,IAAI,QAAQ;AAC7C,QAAM,UAAU,WAAW;AAE3B,QAAM,gBAAgB,IAAoB,CAAC,CAAC;AAC5C,QAAM,QAAQ,IAAI,CAAC;AACnB,QAAM,YAAY,IAAI,KAAK;AAE3B,iBAAe,OAAO;AACpB,QAAI,CAAC,QAAQ,MAAO;AACpB,cAAU,QAAQ;AAClB,QAAI;AACF,YAAM,MAAM,MAAM,QACf,UAAU,EACV,kBAAkB,QAAQ,MAAM,aAAa;AAChD,oBAAc,QAAQ,IAAI;AAC1B,YAAM,QAAQ,IAAI;AAAA,IACpB,UAAE;AACA,gBAAU,QAAQ;AAAA,IACpB;AAAA,EACF;AAEA,YAAU,MAAM;AACd,QAAI,gBAAgB,OAAO;AACzB,WAAK,KAAK;AAAA,IACZ;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,eAAe,SAAS,aAAa;AAAA,IACrC,OAAO,SAAS,KAAK;AAAA,IACrB,WAAW,SAAS,SAAS;AAAA,IAC7B,QAAQ;AAAA,EACV;AACF;AAKO,SAAS,kBAAkB;AAChC,QAAM,EAAE,QAAQ,IAAI,QAAQ;AAC5B,SAAO,SAAS,MAAM,QAAQ,OAAO,iBAAiB,IAAI;AAC5D;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authsome/ui-vue",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Vue.js bindings for AuthSome authentication UI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"clean": "rm -rf dist"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@authsome/ui-core": "^1.
|
|
33
|
+
"@authsome/ui-core": "^1.1.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"vue": "^3.3.0"
|