@@ -9,26 +9,43 @@ definePageMeta({
99const config = useRuntimeConfig ()
1010const { setAccessToken } = useAuth ()
1111
12- onBeforeMount (async () => {
12+ // Use a global state to prevent multiple concurrent callbacks across component re-mounts
13+ const processing = useState (' callback-processing' , () => false )
14+
15+ onMounted (async () => {
16+ // Only process once globally
17+ if (processing .value ) {
18+ return
19+ }
20+
21+ processing .value = true
22+
1323 const { token, redirect } = route .query
14- if (token ) {
15- try {
16- const response = await $fetch <{ token: string }>(
17- ` ${config .public .callbackUrl }?token=${token } ` ,
18- { method: ' GET' },
19- )
20- if (response && response .token ) {
21- setAccessToken (response .token )
22-
23- if (redirect && typeof redirect === ' string' ) {
24- navigateTo (redirect )
25- } else {
26- navigateTo (' /' )
27- }
28- }
29- } catch (e ) {
30- console .error (e )
24+ if (! token || typeof token !== ' string' ) {
25+ processing .value = false
26+ return
27+ }
28+
29+ try {
30+ const response = await $fetch <{ token: string }>(
31+ ` ${config .public .callbackUrl }?token=${token } ` ,
32+ { method: ' GET' },
33+ )
34+
35+ if (response && response .token ) {
36+ setAccessToken (response .token )
37+
38+ const redirectPath =
39+ redirect && typeof redirect === ' string' ? redirect : ' /'
40+
41+ // Use replace to prevent back button issues
42+ await navigateTo (redirectPath , { replace: true })
43+ processing .value = false
44+ } else {
45+ processing .value = false
3146 }
47+ } catch {
48+ processing .value = false
3249 }
3350})
3451 </script >
0 commit comments