@descope/vue-sdk 0.0.0-next-99d31dc5-20240411 → 0.0.0-next-ade1c6f0-20240422
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 +25 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -224,6 +224,24 @@ Descope SDK is automatically refreshes the session token when it is about to exp
|
|
|
224
224
|
If the Descope project settings are configured to manage tokens in cookies.
|
|
225
225
|
you must also configure a custom domain, and set it as the `baseUrl` to the `descope` plugin. See the above [`plugin` usage](#add-descope-plugin-to-your-application) for usage example.
|
|
226
226
|
|
|
227
|
+
### Token Persistence
|
|
228
|
+
|
|
229
|
+
Descope stores two tokens: the session token and the refresh token.
|
|
230
|
+
|
|
231
|
+
- The refresh token is either stored in local storage or an `httpOnly` cookie. This is configurable in the Descope console.
|
|
232
|
+
- The session token is stored in either local storage or a JS cookie. This behavior is configurable via the `sessionTokenViaCookie` prop in the Descope plugin.
|
|
233
|
+
|
|
234
|
+
However, for security reasons, you may choose not to store tokens in the browser. In this case, you can pass `persistTokens: false` to the Descope plugin. This prevents the SDK from storing the tokens in the browser.
|
|
235
|
+
|
|
236
|
+
Notes:
|
|
237
|
+
|
|
238
|
+
- You must configure the refresh token to be stored in an `httpOnly` cookie in the Descope console. Otherwise, the refresh token will not be stored, and when the page is refreshed, the user will be logged out.
|
|
239
|
+
- You can still retrieve the session token using the `useSession` hook.
|
|
240
|
+
|
|
241
|
+
### Last User Persistence
|
|
242
|
+
|
|
243
|
+
Descope stores the last user information in local storage. If you wish to disable this feature, you can pass `storeLastAuthenticatedUser: false` to the Descope plugin. Please note that some features related to the last authenticated user may not function as expected if this behavior is disabled.
|
|
244
|
+
|
|
227
245
|
### Widgets
|
|
228
246
|
|
|
229
247
|
Widgets are components that allow you to expose management features for tenant-based implementation. In certain scenarios, your customers may require the capability to perform managerial actions independently, alleviating the necessity to contact you. Widgets serve as a feature enabling you to delegate these capabilities to your customers in a modular manner.
|
|
@@ -308,10 +326,17 @@ The widget lets you:
|
|
|
308
326
|
|
|
309
327
|
```vue
|
|
310
328
|
<template>
|
|
329
|
+
<!-- admin view: manage all tenant users' access keys -->
|
|
311
330
|
<AccessKeyManagement
|
|
312
331
|
tenant="tenant-id"
|
|
313
332
|
widget-id="access-key-management-widget"
|
|
314
333
|
/>
|
|
334
|
+
|
|
335
|
+
<!-- user view: mange access key for the logged-in tenant's user -->
|
|
336
|
+
<AccessKeyManagement
|
|
337
|
+
tenant="tenant-id"
|
|
338
|
+
widget-id="user-access-key-management-widget"
|
|
339
|
+
/>
|
|
315
340
|
</template>
|
|
316
341
|
|
|
317
342
|
<script setup>
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("vue"),t=require("@descope/web-component"),n=require("@descope/web-js-sdk");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("@descope/user-management-widget"),require("@descope/role-management-widget"),require("@descope/access-key-management-widget"),require("@descope/audit-management-widget");var s=r(t),o=r(n);const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("vue"),t=require("@descope/web-component"),n=require("@descope/web-js-sdk");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("@descope/user-management-widget"),require("@descope/role-management-widget"),require("@descope/access-key-management-widget"),require("@descope/audit-management-widget");var s=r(t),o=r(n);const a=Symbol("$descope"),i={"x-descope-sdk-name":"vue","x-descope-sdk-version":"0.0.0-next-ade1c6f0-20240422"},u="undefined"!=typeof window,d=()=>{const t=e.inject(a);if(!t)throw Error("Missing Descope context, make sure you are using the Descope plugin");return t},l=()=>d().options,c=()=>d().sdk,p=e=>(...t)=>{let n;try{n=e(...t)}catch(e){console.error(e)}return n};let g;const m=e=>{const t=o.default({persistTokens:u,storeLastAuthenticatedUser:u,...e,autoRefresh:u});return g=t,t};g=m({projectId:"temp pid"});const f=()=>u?g?.getSessionToken():(console.warn("Get session token is not supported in SSR"),""),y=()=>u?g?.getRefreshToken():(console.warn("Get refresh token is not supported in SSR"),""),h=p(((e=f(),t)=>g?.getJwtPermissions(e,t))),v=p(((e=f(),t)=>g?.getJwtRoles(e,t))),w=["project-id","base-url","flow-id","^theme","^locale","^tenant","^debug","^telemetryKey","redirect-url","auto-focus","store-last-authenticated-user",".errorTransformer","^form","^client"];var b=e.defineComponent({__name:"Descope",props:{flowId:{type:String,required:!0},tenant:{type:String},theme:{type:String},locale:{type:String},debug:{type:Boolean},telemetryKey:{type:String},redirectUrl:{type:String},autoFocus:{type:Boolean},errorTransformer:{type:Function},form:{type:Object},client:{type:Object}},emits:["success","error","ready"],setup(t,{emit:n}){const r=t;s.default.sdkConfigOverrides={baseHeaders:i,persistTokens:!1,hooks:{get beforeRequest(){return g.httpClient.hooks.beforeRequest},set beforeRequest(e){}}};const{projectId:o,baseUrl:a,storeLastAuthenticatedUser:u}=l(),d=c(),p=e.computed((()=>r.form?JSON.stringify(r.form):"")),m=e.computed((()=>r.client?JSON.stringify(r.client):"")),f=async e=>{await(d.httpClient.hooks?.afterRequest?.({},new Response(JSON.stringify(e.detail)))),n("success",e)},y=e=>n("error",e),h=e=>n("ready",e);return(n,r)=>(e.openBlock(),e.createElementBlock("div",null,[e.createElementVNode("descope-wc",{"project-id":e.unref(o),"base-url":e.unref(a),"flow-id":t.flowId,"^theme":t.theme,"^locale":t.locale,"^tenant":t.tenant,"^debug":t.debug,"^telemetryKey":t.telemetryKey,"redirect-url":t.redirectUrl,"auto-focus":t.autoFocus,"store-last-authenticated-user":e.unref(u),".errorTransformer":t.errorTransformer,"^form":e.unref(p),"^client":e.unref(m),onSuccess:f,onError:y,onReady:h},null,40,w)]))}});b.__file="src/Descope.vue";const S=["project-id","base-url","^theme","^tenant","^debug","widget-id"];var k=e.defineComponent({__name:"UserManagement",props:{tenant:{type:String,required:!0},widgetId:{type:String,required:!0},theme:{type:String},debug:{type:Boolean}},setup(t){const{projectId:n,baseUrl:r}=l();return(s,o)=>(e.openBlock(),e.createElementBlock("div",null,[e.createElementVNode("descope-user-management-widget",{"project-id":e.unref(n),"base-url":e.unref(r),"^theme":t.theme,"^tenant":t.tenant,"^debug":t.debug,"widget-id":t.widgetId},null,8,S)]))}});k.__file="src/UserManagement.vue";const x=["project-id","base-url","^theme","^tenant","^debug","widget-id"];var j=e.defineComponent({__name:"RoleManagement",props:{tenant:{type:String,required:!0},widgetId:{type:String,required:!0},theme:{type:String},debug:{type:Boolean}},setup(t){const{projectId:n,baseUrl:r}=l();return(s,o)=>(e.openBlock(),e.createElementBlock("div",null,[e.createElementVNode("descope-role-management-widget",{"project-id":e.unref(n),"base-url":e.unref(r),"^theme":t.theme,"^tenant":t.tenant,"^debug":t.debug,"widget-id":t.widgetId},null,8,x)]))}});j.__file="src/RoleManagement.vue";const _=["project-id","base-url","^theme","^tenant","^debug","widget-id"];var q=e.defineComponent({__name:"AccessKeyManagement",props:{tenant:{type:String,required:!0},widgetId:{type:String,required:!0},theme:{type:String},debug:{type:Boolean}},setup(t){const{projectId:n,baseUrl:r}=l();return(s,o)=>(e.openBlock(),e.createElementBlock("div",null,[e.createElementVNode("descope-access-key-management-widget",{"project-id":e.unref(n),"base-url":e.unref(r),"^theme":t.theme,"^tenant":t.tenant,"^debug":t.debug,"widget-id":t.widgetId},null,8,_)]))}});q.__file="src/AccessKeyManagement.vue";const R=["project-id","base-url","^theme","^tenant","^debug","widget-id"];var U=e.defineComponent({__name:"AuditManagement",props:{tenant:{type:String,required:!0},widgetId:{type:String,required:!0},theme:{type:String},debug:{type:Boolean}},setup(t){const{projectId:n,baseUrl:r}=l();return(s,o)=>(e.openBlock(),e.createElementBlock("div",null,[e.createElementVNode("descope-audit-management-widget",{"project-id":e.unref(n),"base-url":e.unref(r),"^theme":t.theme,"^tenant":t.tenant,"^debug":t.debug,"widget-id":t.widgetId},null,8,R)]))}});U.__file="src/AuditManagement.vue";const B=e.ref(null);let E;var I={install:function(t,n){const r=m({persistTokens:!0,...n,autoRefresh:!0,baseHeaders:i});E=r;const s=e.ref(null),o=e.ref(""),u=e.ref(null),d=e.ref(null);r.onSessionTokenChange((e=>{o.value=e})),r.onUserChange((e=>{d.value=e}));const l=async()=>{s.value=!0,await r.refresh(),s.value=!1},c=e.computed((()=>null===s.value)),p=e.computed((()=>null===u.value));B.value=()=>new Promise(((t,n)=>{!o.value&&c.value&&l().catch(n),e.watch((()=>s.value),(()=>!s.value&&t(!!e.unref(o))),{immediate:!0})})),t.provide(a,{session:{fetchSession:l,isLoading:e.readonly(s),session:e.readonly(o),isFetchSessionWasNeverCalled:c},user:{fetchUser:async()=>{u.value=!0,await r.me(),u.value=!1},isLoading:e.readonly(u),user:e.readonly(d),isFetchUserWasNeverCalled:p},sdk:r,options:n})}};exports.AccessKeyManagement=q,exports.AuditManagement=U,exports.Descope=b,exports.RoleManagement=j,exports.UserManagement=k,exports.default=I,exports.getJwtPermissions=h,exports.getJwtRoles=v,exports.getRefreshToken=y,exports.getSdk=()=>E,exports.getSessionToken=f,exports.isRefreshTokenExpired=(e=y())=>g?.isJwtExpired(e),exports.isSessionTokenExpired=(e=f())=>g?.isJwtExpired(e),exports.routeGuard=()=>e.unref(B)?.(),exports.useDescope=c,exports.useSession=()=>{const{session:t}=d();return t.isFetchSessionWasNeverCalled.value&&t.fetchSession(),{isLoading:e.computed((()=>t.isLoading.value||t.isFetchSessionWasNeverCalled.value)),sessionToken:t.session,isAuthenticated:e.computed((()=>!!t.session.value))}},exports.useUser=()=>{const{user:t,session:n}=d(),r=()=>{!t.user.value&&n.session.value&&t.fetchUser()};return r(),e.watch(n.session,r),{isLoading:e.computed((()=>t.isLoading.value||t.isFetchUserWasNeverCalled.value)),user:t.user}};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.ts
CHANGED
|
@@ -231,7 +231,9 @@ declare const _default$1: vue.DefineComponent<{
|
|
|
231
231
|
type Options = {
|
|
232
232
|
projectId: string;
|
|
233
233
|
baseUrl?: string;
|
|
234
|
+
persistTokens?: boolean;
|
|
234
235
|
sessionTokenViaCookie?: boolean;
|
|
236
|
+
storeLastAuthenticatedUser?: boolean;
|
|
235
237
|
};
|
|
236
238
|
|
|
237
239
|
declare const useDescope: () => ((({
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{computed as e,watch as t,inject as
|
|
1
|
+
import{computed as e,watch as t,inject as s,defineComponent as n,openBlock as r,createElementBlock as o,createElementVNode as a,unref as i,ref as d,readonly as u}from"vue";import l from"@descope/web-component";import c from"@descope/web-js-sdk";import"@descope/user-management-widget";import"@descope/role-management-widget";import"@descope/access-key-management-widget";import"@descope/audit-management-widget";const p=Symbol("$descope"),g={"x-descope-sdk-name":"vue","x-descope-sdk-version":"0.0.0-next-ade1c6f0-20240422"},m="undefined"!=typeof window,y=()=>{const e=s(p);if(!e)throw Error("Missing Descope context, make sure you are using the Descope plugin");return e},h=()=>y().options,v=()=>y().sdk,f=()=>{const{session:t}=y();return t.isFetchSessionWasNeverCalled.value&&t.fetchSession(),{isLoading:e((()=>t.isLoading.value||t.isFetchSessionWasNeverCalled.value)),sessionToken:t.session,isAuthenticated:e((()=>!!t.session.value))}},b=()=>{const{user:s,session:n}=y(),r=()=>{!s.user.value&&n.session.value&&s.fetchUser()};return r(),t(n.session,r),{isLoading:e((()=>s.isLoading.value||s.isFetchUserWasNeverCalled.value)),user:s.user}},w=e=>(...t)=>{let s;try{s=e(...t)}catch(e){console.error(e)}return s};let S;const k=e=>{const t=c({persistTokens:m,storeLastAuthenticatedUser:m,...e,autoRefresh:m});return S=t,t};S=k({projectId:"temp pid"});const _=()=>m?S?.getSessionToken():(console.warn("Get session token is not supported in SSR"),""),j=()=>m?S?.getRefreshToken():(console.warn("Get refresh token is not supported in SSR"),""),U=(e=_())=>S?.isJwtExpired(e),I=(e=j())=>S?.isJwtExpired(e),R=w(((e=_(),t)=>S?.getJwtPermissions(e,t))),q=w(((e=_(),t)=>S?.getJwtRoles(e,t))),M=["project-id","base-url","flow-id","^theme","^locale","^tenant","^debug","^telemetryKey","redirect-url","auto-focus","store-last-authenticated-user",".errorTransformer","^form","^client"];var T=n({__name:"Descope",props:{flowId:{type:String,required:!0},tenant:{type:String},theme:{type:String},locale:{type:String},debug:{type:Boolean},telemetryKey:{type:String},redirectUrl:{type:String},autoFocus:{type:Boolean},errorTransformer:{type:Function},form:{type:Object},client:{type:Object}},emits:["success","error","ready"],setup(t,{emit:s}){const n=t;l.sdkConfigOverrides={baseHeaders:g,persistTokens:!1,hooks:{get beforeRequest(){return S.httpClient.hooks.beforeRequest},set beforeRequest(e){}}};const{projectId:d,baseUrl:u,storeLastAuthenticatedUser:c}=h(),p=v(),m=e((()=>n.form?JSON.stringify(n.form):"")),y=e((()=>n.client?JSON.stringify(n.client):"")),f=async e=>{await(p.httpClient.hooks?.afterRequest?.({},new Response(JSON.stringify(e.detail)))),s("success",e)},b=e=>s("error",e),w=e=>s("ready",e);return(e,s)=>(r(),o("div",null,[a("descope-wc",{"project-id":i(d),"base-url":i(u),"flow-id":t.flowId,"^theme":t.theme,"^locale":t.locale,"^tenant":t.tenant,"^debug":t.debug,"^telemetryKey":t.telemetryKey,"redirect-url":t.redirectUrl,"auto-focus":t.autoFocus,"store-last-authenticated-user":i(c),".errorTransformer":t.errorTransformer,"^form":i(m),"^client":i(y),onSuccess:f,onError:b,onReady:w},null,40,M)]))}});T.__file="src/Descope.vue";const C=["project-id","base-url","^theme","^tenant","^debug","widget-id"];var A=n({__name:"UserManagement",props:{tenant:{type:String,required:!0},widgetId:{type:String,required:!0},theme:{type:String},debug:{type:Boolean}},setup(e){const{projectId:t,baseUrl:s}=h();return(n,d)=>(r(),o("div",null,[a("descope-user-management-widget",{"project-id":i(t),"base-url":i(s),"^theme":e.theme,"^tenant":e.tenant,"^debug":e.debug,"widget-id":e.widgetId},null,8,C)]))}});A.__file="src/UserManagement.vue";const F=["project-id","base-url","^theme","^tenant","^debug","widget-id"];var L=n({__name:"RoleManagement",props:{tenant:{type:String,required:!0},widgetId:{type:String,required:!0},theme:{type:String},debug:{type:Boolean}},setup(e){const{projectId:t,baseUrl:s}=h();return(n,d)=>(r(),o("div",null,[a("descope-role-management-widget",{"project-id":i(t),"base-url":i(s),"^theme":e.theme,"^tenant":e.tenant,"^debug":e.debug,"widget-id":e.widgetId},null,8,F)]))}});L.__file="src/RoleManagement.vue";const N=["project-id","base-url","^theme","^tenant","^debug","widget-id"];var x=n({__name:"AccessKeyManagement",props:{tenant:{type:String,required:!0},widgetId:{type:String,required:!0},theme:{type:String},debug:{type:Boolean}},setup(e){const{projectId:t,baseUrl:s}=h();return(n,d)=>(r(),o("div",null,[a("descope-access-key-management-widget",{"project-id":i(t),"base-url":i(s),"^theme":e.theme,"^tenant":e.tenant,"^debug":e.debug,"widget-id":e.widgetId},null,8,N)]))}});x.__file="src/AccessKeyManagement.vue";const J=["project-id","base-url","^theme","^tenant","^debug","widget-id"];var K=n({__name:"AuditManagement",props:{tenant:{type:String,required:!0},widgetId:{type:String,required:!0},theme:{type:String},debug:{type:Boolean}},setup(e){const{projectId:t,baseUrl:s}=h();return(n,d)=>(r(),o("div",null,[a("descope-audit-management-widget",{"project-id":i(t),"base-url":i(s),"^theme":e.theme,"^tenant":e.tenant,"^debug":e.debug,"widget-id":e.widgetId},null,8,J)]))}});K.__file="src/AuditManagement.vue";const B=d(null),O=()=>i(B)?.();let D;const W=()=>D;var E={install:function(s,n){const r=k({persistTokens:!0,...n,autoRefresh:!0,baseHeaders:g});D=r;const o=d(null),a=d(""),l=d(null),c=d(null);r.onSessionTokenChange((e=>{a.value=e})),r.onUserChange((e=>{c.value=e}));const m=async()=>{o.value=!0,await r.refresh(),o.value=!1},y=e((()=>null===o.value)),h=e((()=>null===l.value));B.value=()=>new Promise(((e,s)=>{!a.value&&y.value&&m().catch(s),t((()=>o.value),(()=>!o.value&&e(!!i(a))),{immediate:!0})})),s.provide(p,{session:{fetchSession:m,isLoading:u(o),session:u(a),isFetchSessionWasNeverCalled:y},user:{fetchUser:async()=>{l.value=!0,await r.me(),l.value=!1},isLoading:u(l),user:u(c),isFetchUserWasNeverCalled:h},sdk:r,options:n})}};export{x as AccessKeyManagement,K as AuditManagement,T as Descope,L as RoleManagement,A as UserManagement,E as default,R as getJwtPermissions,q as getJwtRoles,j as getRefreshToken,W as getSdk,_ as getSessionToken,I as isRefreshTokenExpired,U as isSessionTokenExpired,O as routeGuard,v as useDescope,f as useSession,b as useUser};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|