@mole-auth/vue 1.0.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.mts +57 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +24 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Plugin } from 'vue';
|
|
2
|
+
import { User, LoginParams, RegisterParams, UpdateUserParams, ForgotPasswordParams, ResetPasswordParams } from '@mole-auth/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AuthSaaS Vue 集成
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Auth 实例类型
|
|
10
|
+
*/
|
|
11
|
+
interface AuthInstance {
|
|
12
|
+
user: User | null;
|
|
13
|
+
loading: boolean;
|
|
14
|
+
authenticated: boolean;
|
|
15
|
+
login: (data: LoginParams) => Promise<void>;
|
|
16
|
+
register: (data: RegisterParams) => Promise<void>;
|
|
17
|
+
logout: () => Promise<void>;
|
|
18
|
+
updateUser: (data: UpdateUserParams) => Promise<User>;
|
|
19
|
+
forgotPassword: (data: ForgotPasswordParams) => Promise<any>;
|
|
20
|
+
resetPassword: (data: ResetPasswordParams) => Promise<any>;
|
|
21
|
+
loginWithOAuth: (provider: "google" | "github" | "qq" | "wechat") => void;
|
|
22
|
+
/**
|
|
23
|
+
* 使用标准 OAuth2 授权码流程登录 AuthSaaS 平台
|
|
24
|
+
*/
|
|
25
|
+
authorizeWithOAuth2: (config: {
|
|
26
|
+
clientId: string;
|
|
27
|
+
redirectUri: string;
|
|
28
|
+
scope?: string;
|
|
29
|
+
state?: string;
|
|
30
|
+
codeChallenge?: string;
|
|
31
|
+
codeChallengeMethod?: "plain" | "S256";
|
|
32
|
+
}) => void;
|
|
33
|
+
/**
|
|
34
|
+
* 使用授权码换取访问令牌
|
|
35
|
+
*/
|
|
36
|
+
exchangeCodeForToken: (params: {
|
|
37
|
+
code: string;
|
|
38
|
+
redirectUri: string;
|
|
39
|
+
clientId: string;
|
|
40
|
+
clientSecret?: string;
|
|
41
|
+
}) => Promise<{
|
|
42
|
+
user: User;
|
|
43
|
+
token: string;
|
|
44
|
+
}>;
|
|
45
|
+
refreshUser: () => Promise<void>;
|
|
46
|
+
client: any;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Vue Plugin
|
|
50
|
+
*/
|
|
51
|
+
declare const AuthPlugin: Plugin;
|
|
52
|
+
/**
|
|
53
|
+
* useAuth Composable
|
|
54
|
+
*/
|
|
55
|
+
declare function useAuth(): AuthInstance;
|
|
56
|
+
|
|
57
|
+
export { type AuthInstance, AuthPlugin, useAuth };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Plugin } from 'vue';
|
|
2
|
+
import { User, LoginParams, RegisterParams, UpdateUserParams, ForgotPasswordParams, ResetPasswordParams } from '@mole-auth/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AuthSaaS Vue 集成
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Auth 实例类型
|
|
10
|
+
*/
|
|
11
|
+
interface AuthInstance {
|
|
12
|
+
user: User | null;
|
|
13
|
+
loading: boolean;
|
|
14
|
+
authenticated: boolean;
|
|
15
|
+
login: (data: LoginParams) => Promise<void>;
|
|
16
|
+
register: (data: RegisterParams) => Promise<void>;
|
|
17
|
+
logout: () => Promise<void>;
|
|
18
|
+
updateUser: (data: UpdateUserParams) => Promise<User>;
|
|
19
|
+
forgotPassword: (data: ForgotPasswordParams) => Promise<any>;
|
|
20
|
+
resetPassword: (data: ResetPasswordParams) => Promise<any>;
|
|
21
|
+
loginWithOAuth: (provider: "google" | "github" | "qq" | "wechat") => void;
|
|
22
|
+
/**
|
|
23
|
+
* 使用标准 OAuth2 授权码流程登录 AuthSaaS 平台
|
|
24
|
+
*/
|
|
25
|
+
authorizeWithOAuth2: (config: {
|
|
26
|
+
clientId: string;
|
|
27
|
+
redirectUri: string;
|
|
28
|
+
scope?: string;
|
|
29
|
+
state?: string;
|
|
30
|
+
codeChallenge?: string;
|
|
31
|
+
codeChallengeMethod?: "plain" | "S256";
|
|
32
|
+
}) => void;
|
|
33
|
+
/**
|
|
34
|
+
* 使用授权码换取访问令牌
|
|
35
|
+
*/
|
|
36
|
+
exchangeCodeForToken: (params: {
|
|
37
|
+
code: string;
|
|
38
|
+
redirectUri: string;
|
|
39
|
+
clientId: string;
|
|
40
|
+
clientSecret?: string;
|
|
41
|
+
}) => Promise<{
|
|
42
|
+
user: User;
|
|
43
|
+
token: string;
|
|
44
|
+
}>;
|
|
45
|
+
refreshUser: () => Promise<void>;
|
|
46
|
+
client: any;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Vue Plugin
|
|
50
|
+
*/
|
|
51
|
+
declare const AuthPlugin: Plugin;
|
|
52
|
+
/**
|
|
53
|
+
* useAuth Composable
|
|
54
|
+
*/
|
|
55
|
+
declare function useAuth(): AuthInstance;
|
|
56
|
+
|
|
57
|
+
export { type AuthInstance, AuthPlugin, useAuth };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var vue=require('vue'),core=require('@mole-auth/core');var m=Object.defineProperty,v=Object.defineProperties;var f=Object.getOwnPropertyDescriptors;var g=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var c=(r,t,e)=>t in r?m(r,t,{enumerable:true,configurable:true,writable:true,value:e}):r[t]=e,d=(r,t)=>{for(var e in t||(t={}))w.call(t,e)&&c(r,e,t[e]);if(g)for(var e of g(t))A.call(t,e)&&c(r,e,t[e]);return r},h=(r,t)=>v(r,f(t));var o=(r,t,e)=>new Promise((s,a)=>{var n=i=>{try{u(e.next(i));}catch(l){a(l);}},p=i=>{try{u(e.throw(i));}catch(l){a(l);}},u=i=>i.done?s(i.value):Promise.resolve(i.value).then(n,p);u((e=e.apply(r,t)).next());});var y=Symbol("auth");function S(r){let t=vue.ref(null),e=vue.ref(true),s=core.createAuthSaaS(h(d({},r),{onAuthChange:(a,n)=>{t.value=a,e.value=false;}}));return s.getToken().then(a=>{s.getUser().then(n=>{a&&n&&(t.value=n),e.value=false;});}),{get user(){return t.value},get loading(){return e.value},get authenticated(){return !!t.value},login:a=>o(null,null,function*(){e.value=true;try{let n=yield s.login(a);t.value=n.user;}finally{e.value=false;}}),register:a=>o(null,null,function*(){e.value=true;try{let n=yield s.register(a);t.value=n.user;}finally{e.value=false;}}),logout:()=>o(null,null,function*(){e.value=true;try{yield s.logout(),t.value=null;}finally{e.value=false;}}),updateUser:a=>o(null,null,function*(){let n=yield s.updateUser(a);return t.value=n,n}),forgotPassword:a=>o(null,null,function*(){return yield s.forgotPassword(a)}),resetPassword:a=>o(null,null,function*(){return yield s.resetPassword(a)}),loginWithOAuth:a=>{s.loginWithOAuth(a);},authorizeWithOAuth2:a=>{s.authorizeWithOAuth2(a);},exchangeCodeForToken:a=>o(null,null,function*(){let n=yield s.exchangeCodeForToken(a);return t.value=n.user,n}),refreshUser:()=>o(null,null,function*(){e.value=true;try{let a=yield s.getCurrentUser();t.value=a;}finally{e.value=false;}}),client:s}}var R={install(r,t){let e=S(t);r.provide(y,e),r.config.globalProperties.$auth=e;}};function W(){let r=vue.inject(y);if(!r)throw new Error("useAuth must be used within an app with AuthPlugin installed");return r}exports.AuthPlugin=R;exports.useAuth=W;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {inject,ref}from'vue';import {createAuthSaaS}from'@mole-auth/core';var m=Object.defineProperty,v=Object.defineProperties;var f=Object.getOwnPropertyDescriptors;var g=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var c=(r,t,e)=>t in r?m(r,t,{enumerable:true,configurable:true,writable:true,value:e}):r[t]=e,d=(r,t)=>{for(var e in t||(t={}))w.call(t,e)&&c(r,e,t[e]);if(g)for(var e of g(t))A.call(t,e)&&c(r,e,t[e]);return r},h=(r,t)=>v(r,f(t));var o=(r,t,e)=>new Promise((s,a)=>{var n=i=>{try{u(e.next(i));}catch(l){a(l);}},p=i=>{try{u(e.throw(i));}catch(l){a(l);}},u=i=>i.done?s(i.value):Promise.resolve(i.value).then(n,p);u((e=e.apply(r,t)).next());});var y=Symbol("auth");function S(r){let t=ref(null),e=ref(true),s=createAuthSaaS(h(d({},r),{onAuthChange:(a,n)=>{t.value=a,e.value=false;}}));return s.getToken().then(a=>{s.getUser().then(n=>{a&&n&&(t.value=n),e.value=false;});}),{get user(){return t.value},get loading(){return e.value},get authenticated(){return !!t.value},login:a=>o(null,null,function*(){e.value=true;try{let n=yield s.login(a);t.value=n.user;}finally{e.value=false;}}),register:a=>o(null,null,function*(){e.value=true;try{let n=yield s.register(a);t.value=n.user;}finally{e.value=false;}}),logout:()=>o(null,null,function*(){e.value=true;try{yield s.logout(),t.value=null;}finally{e.value=false;}}),updateUser:a=>o(null,null,function*(){let n=yield s.updateUser(a);return t.value=n,n}),forgotPassword:a=>o(null,null,function*(){return yield s.forgotPassword(a)}),resetPassword:a=>o(null,null,function*(){return yield s.resetPassword(a)}),loginWithOAuth:a=>{s.loginWithOAuth(a);},authorizeWithOAuth2:a=>{s.authorizeWithOAuth2(a);},exchangeCodeForToken:a=>o(null,null,function*(){let n=yield s.exchangeCodeForToken(a);return t.value=n.user,n}),refreshUser:()=>o(null,null,function*(){e.value=true;try{let a=yield s.getCurrentUser();t.value=a;}finally{e.value=false;}}),client:s}}var R={install(r,t){let e=S(t);r.provide(y,e),r.config.globalProperties.$auth=e;}};function W(){let r=inject(y);if(!r)throw new Error("useAuth must be used within an app with AuthPlugin installed");return r}export{R as AuthPlugin,W as useAuth};
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mole-auth/vue",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"private": false,
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsup"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [],
|
|
19
|
+
"author": "zhengwei",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@mole-auth/core": "^1.0.0",
|
|
22
|
+
"vue": "^3.5.27"
|
|
23
|
+
}
|
|
24
|
+
}
|