@@ -100,6 +100,10 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
100
100
101
101
const scopes : string [ ] = [ 'openid' , 'profile' , 'offline_access' , msalConfig . auth . clientId ]
102
102
103
+ const router = useRouter ( )
104
+ const { userClientWithAuth } = useAPI ( )
105
+ const localePath = useLocalePath ( )
106
+
103
107
const accounts = useState < AccountInfo [ ] | undefined > ( 'useMSAL.accounts' )
104
108
const interactionStatus = useState < InteractionStatus | undefined > ( 'useMSAL.interactionStatus' )
105
109
@@ -134,6 +138,24 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
134
138
throw new Error ( 'failed to init MSAL instance' , { cause : error } )
135
139
}
136
140
141
+ const signOut = ( ) : Promise < void > => {
142
+ const logoutRequest = {
143
+ postLogoutRedirectUri : msalConfig . auth . redirectUri ,
144
+ mainWindowRedirectUri : msalConfig . auth . logoutUri ,
145
+ }
146
+ const userClient = userClientWithAuth ( '' ) // Logging out doesn't require auth.
147
+ return Promise . all ( [
148
+ userClient . logout ( ) ,
149
+ instance . logoutPopup ( logoutRequest ) ,
150
+ ] )
151
+ . catch ( ( e ) => { console . log ( 'failed to log out' , e ) } )
152
+ . then ( ( ) => { /* cast to void */ } )
153
+ . finally ( ( ) => {
154
+ isAuthenticated . value = false
155
+ void router . push ( localePath ( '/' ) )
156
+ } )
157
+ }
158
+
137
159
const handleResponse = async ( response : AuthenticationResult , force = false ) : Promise < AuthenticationResult > => {
138
160
if ( ! response ?. account ) {
139
161
return await Promise . resolve ( response )
@@ -183,10 +205,6 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
183
205
console . log ( 'multiple accounts found, user needs to select one' )
184
206
}
185
207
186
- const router = useRouter ( )
187
- const { userClientWithAuth } = useAPI ( )
188
- const localePath = useLocalePath ( )
189
-
190
208
const account = computed ( ( ) => {
191
209
if ( ! accounts . value ) {
192
210
return undefined
@@ -278,24 +296,6 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
278
296
} )
279
297
}
280
298
281
- const signOut = ( ) : Promise < void > => {
282
- const logoutRequest = {
283
- postLogoutRedirectUri : msalConfig . auth . redirectUri ,
284
- mainWindowRedirectUri : msalConfig . auth . logoutUri ,
285
- }
286
- const userClient = userClientWithAuth ( '' ) // Logging out doesn't require auth.
287
- return Promise . all ( [
288
- userClient . logout ( ) ,
289
- instance . logoutPopup ( logoutRequest ) ,
290
- ] )
291
- . catch ( ( e ) => { console . log ( 'failed to log out' , e ) } )
292
- . then ( ( ) => { /* cast to void */ } )
293
- . finally ( ( ) => {
294
- isAuthenticated . value = false
295
- void router . push ( localePath ( '/' ) )
296
- } )
297
- }
298
-
299
299
return {
300
300
provide : {
301
301
msal : {
0 commit comments