File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { getCurrentUser } from 'vuefire'
22import { defineNuxtRouteMiddleware , navigateTo } from '#imports'
33
4- export default defineNuxtRouteMiddleware ( async ( ) => {
4+ export default defineNuxtRouteMiddleware ( async ( to ) => {
55 const currentUser = await getCurrentUser ( )
66
7- // redirect the user to the home page
8- // if the user is already signed in
7+ // Redirect if the user is already signed in
98 if ( currentUser ) {
10- return navigateTo ( { path : '/' } )
9+ const redirect = to . query . redirect as string | undefined
10+ return navigateTo ( redirect || '/' )
1111 }
1212} )
Original file line number Diff line number Diff line change @@ -20,10 +20,12 @@ import {
2020 definePageMeta ,
2121 useSeoMeta ,
2222 navigateTo ,
23+ useRoute ,
2324} from ' #imports'
2425
2526// App state
2627const nuxtifyConfig = useNuxtifyConfig ()
28+ const route = useRoute ()
2729const { xs } = useDisplay ()
2830const errorMessage = useErrorMessage ()
2931
@@ -69,7 +71,8 @@ async function submitForm() {
6971 await signInWithEmailAndPassword (auth , email .value , password .value )
7072
7173 // Redirect
72- navigateTo (' /' )
74+ const redirect = route .query .redirect as string | undefined
75+ navigateTo (redirect || ' /' )
7376 }
7477 catch (error ) {
7578 let message = ' An unexpected error occurred.'
@@ -153,7 +156,11 @@ async function signinWithGoogle() {
153156 }
154157 if (import .meta .dev ) {
155158 // Use this with localhost, still might need to refresh or manually update address bar
156- signInWithPopup (auth , googleProvider )
159+ await signInWithPopup (auth , googleProvider )
160+
161+ // Redirect
162+ const redirect = route .query .redirect as string | undefined
163+ navigateTo (redirect || ' /' )
157164 }
158165 else {
159166 // Doesn't work on localhost
Original file line number Diff line number Diff line change @@ -19,10 +19,12 @@ import {
1919 definePageMeta ,
2020 useSeoMeta ,
2121 navigateTo ,
22+ useRoute ,
2223} from ' #imports'
2324
2425// App state
2526const nuxtifyConfig = useNuxtifyConfig ()
27+ const route = useRoute ()
2628const { xs } = useDisplay ()
2729const errorMessage = useErrorMessage ()
2830
@@ -66,7 +68,8 @@ async function submitForm() {
6668 await createUserWithEmailAndPassword (auth , email .value , password .value )
6769
6870 // Redirect
69- navigateTo (' /' )
71+ const redirect = route .query .redirect as string | undefined
72+ navigateTo (redirect || ' /' )
7073 }
7174 catch (error ) {
7275 let message = ' An unexpected error occurred.'
@@ -106,7 +109,11 @@ async function signinWithGoogle() {
106109 }
107110 if (import .meta .dev ) {
108111 // Use this with localhost, still might need to refresh or manually update address bar
109- signInWithPopup (auth , googleProvider )
112+ await signInWithPopup (auth , googleProvider )
113+
114+ // Redirect
115+ const redirect = route .query .redirect as string | undefined
116+ navigateTo (redirect || ' /' )
110117 }
111118 else {
112119 // Doesn't work on localhost
You can’t perform that action at this time.
0 commit comments