1- import { Oidc } from "./oidc-client.js" ;
1+ import { Oidc } from "./oidc-client.esm. js" ;
22
33let client = null ;
44
@@ -29,6 +29,27 @@ class InMemoryWebStorageStateStore {
2929 }
3030}
3131
32+ async function updateUI ( ) {
33+ const user = await client . getUser ( ) ;
34+ const isAuthenticated = Boolean ( user ) ;
35+
36+ document . getElementById ( "btn-login" ) . disabled = isAuthenticated ;
37+ document . getElementById ( "btn-logout" ) . disabled = ! isAuthenticated ;
38+ document . getElementById ( "txt-email" ) . textContent = isAuthenticated
39+ ? user . profile . email || user . profile . sub
40+ : "(please log in)" ;
41+ }
42+
43+ async function refresh ( ) {
44+ console . log ( "refresh token" ) ;
45+ client . startSilentRenew ( ) ;
46+ }
47+
48+ async function logout ( ) {
49+ client . removeUser ( ) ;
50+ updateUI ( ) ;
51+ }
52+
3253async function onload ( ) {
3354 const settings_response = await fetch ( "/auth_settings.json" ) ;
3455 const settings = await settings_response . json ( ) ;
@@ -43,39 +64,19 @@ async function onload() {
4364 if ( query . includes ( "code=" ) && query . includes ( "state=" ) ) {
4465 // Process the redirect callback from the identity provider
4566 const user = await client . signinCallback ( ) ;
46- console . log ( user ) ; // Don't do this IRL!
67+ // Don't do this IRL!
68+ console . log ( user ) ;
4769 // Use replaceState to redirect the user away and remove the querystring parameters
4870 window . history . replaceState ( { } , document . title , "/" ) ;
4971 }
5072
5173 updateUI ( ) ;
5274}
5375
54- async function updateUI ( ) {
55- const user = await client . getUser ( ) ;
56- const isAuthenticated = Boolean ( user ) ;
57-
58- document . getElementById ( "btn-login" ) . disabled = isAuthenticated ;
59- document . getElementById ( "btn-logout" ) . disabled = ! isAuthenticated ;
60- document . getElementById ( "txt-email" ) . textContent = isAuthenticated
61- ? user . profile . email || user . profile . sub
62- : "(please log in)" ;
63- }
64-
6576async function login ( ) {
6677 client . signinRedirect ( ) ;
6778}
6879
69- async function logout ( ) {
70- client . removeUser ( ) ;
71- updateUI ( ) ;
72- }
73-
74- async function refresh ( ) {
75- console . log ( "refresh token" ) ;
76- client . startSilentRenew ( ) ;
77- }
78-
7980async function _whoami ( endpoint ) {
8081 const user = await client . getUser ( ) ;
8182 try {
0 commit comments