Skip to content

Commit 6aff0d0

Browse files
committed
Minor implementation example improvement
1 parent 6cf9b86 commit 6aff0d0

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

src/index.html

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@
6262
diam.
6363
</p>
6464
</div>
65-
<script type="module" src="../dist/index.js"></script>
66-
<script>
67-
</script>
68-
<script type="module">
65+
<script src="https://unpkg.com/@frontify/frontify-authenticator@latest/dist/index.js"></script>
66+
<script">
6967
import {authorize, revoke, refresh} from "../dist/index.es.js";
7068
const POPUP_CONFIG = {
7169
width: 800,
@@ -80,45 +78,58 @@
8078
scopes: ["basic:read", "finder:read", "account:read"],
8179
};
8280

83-
let domain = '';
84-
let token = null;
85-
81+
let token = localStorage.getItem('FrontifyAuthenticatorToken');
82+
8683
function authorizeAction() {
87-
// handle domain window
8884
if (!token) {
89-
authorize(AUTHORIZATION_CONFIG, POPUP_CONFIG).then(res => {
90-
if (res) {
91-
domain = res.domain;
92-
token = res;
93-
}
94-
}).catch((err) => {
95-
console.log(err);
96-
});
97-
} else {
98-
console.log(token);
85+
FrontifyAuthenticator.authorize(AUTHORIZATION_CONFIG, POPUP_CONFIG)
86+
.then((res) => {
87+
if (res) {
88+
localStorage.setItem('FrontifyAuthenticatorToken', JSON.stringify(res));
89+
token = localStorage.getItem('FrontifyAuthenticatorToken');
90+
}
91+
})
92+
.catch((err) => {
93+
console.log(err);
94+
});
9995
}
10096
}
10197

102-
10398
function revokeAction() {
10499
if (!token) {
100+
console.log('Nothing to revoke! No token available');
105101
return;
106102
}
107103

108-
revoke(token).then(res => {
109-
token = null;
110-
delete(AUTHORIZATION_CONFIG.domain);
111-
});
104+
FrontifyAuthenticator.revoke(JSON.parse(token))
105+
.then((res) => {
106+
if (res) {
107+
localStorage.removeItem('FrontifyAuthenticatorToken');
108+
token = null;
109+
delete AUTHORIZATION_CONFIG.domain;
110+
}
111+
})
112+
.catch((error) => {
113+
console.log(error);
114+
});
112115
}
113116

114117
function refreshAction() {
115118
if (!token) {
119+
console.log('Nothing to refresh! No token available');
116120
return;
117121
}
118122

119-
refresh(token).then(res => {
120-
token = res;
121-
});
123+
FrontifyAuthenticator.refresh(JSON.parse(token))
124+
.then((res) => {
125+
if (res) {
126+
localStorage.setItem('FrontifyAuthenticatorToken', JSON.stringify(res));
127+
token = localStorage.getItem('FrontifyAuthenticatorToken');
128+
}
129+
})
130+
.catch((error) => {
131+
console.log(error);
132+
});
122133
}
123134

124135
document.getElementById('authorize').addEventListener('click', authorizeAction);

0 commit comments

Comments
 (0)