@functionalcms/svelte-components 0.8.3 → 0.8.5
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/authStore.js +17 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/authStore.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { readonly, writable } from "svelte/store";
|
|
1
|
+
import { get, readonly, writable } from "svelte/store";
|
|
2
2
|
import { PublicClientApplication } from "@azure/msal-browser";
|
|
3
3
|
const isAuthenticated = writable(false);
|
|
4
4
|
const accessToken = writable('');
|
|
5
5
|
const userId = writable('');
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const msal = writable(null);
|
|
7
|
+
const authConfig = writable({});
|
|
8
8
|
const getMSALConfig = (config) => {
|
|
9
9
|
return {
|
|
10
10
|
auth: {
|
|
@@ -39,9 +39,10 @@ const handleToken = (token) => {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
const logUsingCookies = async (config) => {
|
|
42
|
-
const
|
|
42
|
+
const msalInstance = get(msal);
|
|
43
|
+
const accounts = msalInstance.getAllAccounts();
|
|
43
44
|
if (accounts.length > 0) {
|
|
44
|
-
const token = await
|
|
45
|
+
const token = await msalInstance.acquireTokenSilent(getTokenRequest(config, accounts[0]));
|
|
45
46
|
handleToken(token);
|
|
46
47
|
}
|
|
47
48
|
};
|
|
@@ -49,17 +50,23 @@ export const authStore = {
|
|
|
49
50
|
isAuthenticated: readonly(isAuthenticated),
|
|
50
51
|
userId: readonly(userId),
|
|
51
52
|
accessToken: readonly(accessToken),
|
|
53
|
+
// msal: readonly(msal),
|
|
54
|
+
// authConfig: readonly(authConfig),
|
|
52
55
|
initialise: async (config) => {
|
|
53
|
-
|
|
54
|
-
await
|
|
56
|
+
const msalInstance = new PublicClientApplication(getMSALConfig(config));
|
|
57
|
+
await msalInstance.initialize();
|
|
55
58
|
await logUsingCookies(config);
|
|
56
|
-
|
|
59
|
+
msal.set(msalInstance);
|
|
60
|
+
authConfig.set(config);
|
|
57
61
|
},
|
|
58
62
|
signIn: async () => {
|
|
59
|
-
const
|
|
63
|
+
const config = get(authConfig);
|
|
64
|
+
const msalInstance = get(msal);
|
|
65
|
+
const loginResponse = await msalInstance.loginPopup(getLoginRequest(config));
|
|
60
66
|
handleToken(loginResponse);
|
|
61
67
|
},
|
|
62
68
|
signOut: async () => {
|
|
63
|
-
|
|
69
|
+
const msalInstance = get(msal);
|
|
70
|
+
await msalInstance.logoutPopup({});
|
|
64
71
|
},
|
|
65
72
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import Box from './components/Box.svelte';
|
|
|
2
2
|
import Hero from './components/Hero.svelte';
|
|
3
3
|
import Header from './components/Header.svelte';
|
|
4
4
|
import Footer from './components/Footer.svelte';
|
|
5
|
-
import { authStore
|
|
6
|
-
export { Box, Hero, Header, Footer, authStore
|
|
5
|
+
import { authStore } from './authStore.js';
|
|
6
|
+
export { Box, Hero, Header, Footer, authStore };
|
package/dist/index.js
CHANGED
|
@@ -4,4 +4,4 @@ import Hero from './components/Hero.svelte';
|
|
|
4
4
|
import Header from './components/Header.svelte';
|
|
5
5
|
import Footer from './components/Footer.svelte';
|
|
6
6
|
import { authStore } from './authStore.js';
|
|
7
|
-
export { Box, Hero, Header, Footer, authStore
|
|
7
|
+
export { Box, Hero, Header, Footer, authStore };
|