@crossid/vue-wrapper
Advanced tools
Comparing version 1.0.4 to 1.0.5
{ | ||
"name": "@crossid/vue-wrapper", | ||
"scope": "@crossid", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A wrapper for the crossid oauth2 client for vue3", | ||
@@ -17,3 +17,3 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"@crossid/crossid-spa-js": "^0.0.3", | ||
"@crossid/crossid-spa-js": "^0.0.4", | ||
"typescript": "^4.3.5", | ||
@@ -20,0 +20,0 @@ "vue": "^3.0.0" |
@@ -1,15 +0,12 @@ | ||
import { Client as CrossidClient } from "@crossid/crossid-spa-js"; | ||
import { Client as CrossidClient, } from "@crossid/crossid-spa-js"; | ||
import { defineComponent, h } from "vue"; | ||
export function create(options) { | ||
const client = new CrossidClient(options); | ||
const internalStore = { | ||
user: null, | ||
isAuthenticated: false, | ||
}; | ||
const data = { internalStore, client }; | ||
const data = { client }; | ||
const authProvider = defineComponent({ | ||
render() { | ||
return h("slot", null, this.$slots.default({ | ||
user: this.internalStore.user, | ||
isAuthenticated: this.internalStore.isAuthenticated, | ||
accessToken: this.accessToken, | ||
user: this.user, | ||
isAuthenticated: this.isAuthenticated, | ||
loginRedirect: this.loginRedirect, | ||
@@ -23,6 +20,2 @@ })); | ||
} | ||
else { | ||
this.internalStore.isAuthenticated = !!user; | ||
this.internalStore.user = user; | ||
} | ||
}, | ||
@@ -36,2 +29,12 @@ data() { | ||
methods: { | ||
async accessToken(opts) { | ||
return client.getAccessToken(opts); | ||
}, | ||
async user(opts) { | ||
return client.getUser(opts); | ||
}, | ||
async isAuthenticated(opts) { | ||
const user = client.getUser(opts); | ||
return !!user; | ||
}, | ||
loginRedirect(audience, scope, returnTo) { | ||
@@ -50,4 +53,5 @@ const options = { | ||
return h("span", null, this.$slots.default({ | ||
user: this.internalStore.user, | ||
isAuthenticated: this.internalStore.isAuthenticated, | ||
accessToken: this.accessToken, | ||
user: this.user, | ||
isAuthenticated: this.isAuthenticated, | ||
})); | ||
@@ -62,2 +66,12 @@ }, | ||
methods: { | ||
async accessToken(opts) { | ||
return client.getAccessToken(opts); | ||
}, | ||
async user(opts) { | ||
return client.getUser(opts); | ||
}, | ||
async isAuthenticated(opts) { | ||
const user = client.getUser(opts); | ||
return !!user; | ||
}, | ||
async loginRedirectCallback() { | ||
@@ -68,5 +82,2 @@ await this.client.handleRedirectCallback(); | ||
// const scope = sessionStorage.getItem('crossid.spa-js@scope') | ||
const user = await client.getUser(); | ||
internalStore.user = user || null; | ||
internalStore.isAuthenticated = !!user; | ||
window.history.replaceState(null, null, returnTo); | ||
@@ -73,0 +84,0 @@ this.$emit("navigate"); |
@@ -1,5 +0,10 @@ | ||
import { Client as CrossidClient, IDToken } from "@crossid/crossid-spa-js"; | ||
import { | ||
Client as CrossidClient, | ||
IDToken, | ||
GetUserOpts, | ||
GetAccessTokenOpts, | ||
} from "@crossid/crossid-spa-js"; | ||
// todo replace with real opts once they are exported | ||
type ClientOpts = any; | ||
import { Component, defineComponent, h, onMounted } from "vue"; | ||
import { Component, defineComponent, h } from "vue"; | ||
@@ -9,2 +14,3 @@ interface IInternalStore { | ||
user: IDToken | null; | ||
loadState: string; | ||
} | ||
@@ -14,8 +20,4 @@ | ||
const client = new CrossidClient(options); | ||
const internalStore: IInternalStore = { | ||
user: null, | ||
isAuthenticated: false, | ||
}; | ||
const data = { internalStore, client }; | ||
const data = { client }; | ||
@@ -28,4 +30,5 @@ const authProvider = defineComponent({ | ||
this.$slots.default({ | ||
user: this.internalStore.user, | ||
isAuthenticated: this.internalStore.isAuthenticated, | ||
accessToken: this.accessToken, | ||
user: this.user, | ||
isAuthenticated: this.isAuthenticated, | ||
loginRedirect: this.loginRedirect, | ||
@@ -45,5 +48,2 @@ }) | ||
); | ||
} else { | ||
this.internalStore.isAuthenticated = !!user; | ||
this.internalStore.user = user; | ||
} | ||
@@ -61,2 +61,15 @@ }, | ||
methods: { | ||
async accessToken(opts?: GetAccessTokenOpts): Promise<string> { | ||
return client.getAccessToken(opts); | ||
}, | ||
async user(opts?: GetUserOpts): Promise<IDToken> { | ||
return client.getUser(opts); | ||
}, | ||
async isAuthenticated(opts?: GetUserOpts): Promise<boolean> { | ||
const user = client.getUser(opts); | ||
return !!user; | ||
}, | ||
loginRedirect(audience: string, scope: string, returnTo: string) { | ||
@@ -79,4 +92,5 @@ const options = { | ||
this.$slots.default({ | ||
user: this.internalStore.user, | ||
isAuthenticated: this.internalStore.isAuthenticated, | ||
accessToken: this.accessToken, | ||
user: this.user, | ||
isAuthenticated: this.isAuthenticated, | ||
}) | ||
@@ -94,2 +108,15 @@ ); | ||
methods: { | ||
async accessToken(opts?: GetAccessTokenOpts): Promise<string> { | ||
return client.getAccessToken(opts); | ||
}, | ||
async user(opts?: GetUserOpts): Promise<IDToken> { | ||
return client.getUser(opts); | ||
}, | ||
async isAuthenticated(opts?: GetUserOpts): Promise<boolean> { | ||
const user = client.getUser(opts); | ||
return !!user; | ||
}, | ||
async loginRedirectCallback() { | ||
@@ -101,6 +128,2 @@ await this.client.handleRedirectCallback(); | ||
const user = await client.getUser(); | ||
internalStore.user = user || null; | ||
internalStore.isAuthenticated = !!user; | ||
window.history.replaceState(null, null, returnTo); | ||
@@ -107,0 +130,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13079
238
+ Added@crossid/crossid-spa-js@0.0.4(transitive)
- Removed@crossid/crossid-spa-js@0.0.3(transitive)