@@ -28,6 +28,21 @@ const auth = useFirebaseAuth()!
28
28
const user = useCurrentUser ()
29
29
let credential: AuthCredential | null = null
30
30
31
+ const route = useRoute ()
32
+ const router = useRouter ()
33
+
34
+ // automatically redirect the user if they are logged in but was rejected on the server beacuse of an outdated cookie
35
+ onMounted (async () => {
36
+ const currentUser = await getCurrentUser ()
37
+ if (
38
+ currentUser &&
39
+ route .query .redirect &&
40
+ typeof route .query .redirect === ' string'
41
+ ) {
42
+ router .push (route .query .redirect )
43
+ }
44
+ })
45
+
31
46
// new user
32
47
const email = ref (' ' )
33
48
const password = ref (' ' )
@@ -82,30 +97,20 @@ onMounted(() => {
82
97
<template >
83
98
<main >
84
99
<h1 >Auth playground</h1 >
85
- <button @click =" signOut(auth)" >
86
- SignOut
87
- </button >
88
- <button @click =" signInAnonymously(auth)" >
89
- Anonymous signIn
90
- </button >
91
- <button @click =" signinPopup()" >
92
- Signin Google (popup)
93
- </button >
94
- <button @click =" signinRedirect()" >
95
- Signin Google (redirect)
96
- </button >
97
- <button @click =" changeUserImage" >
98
- Change User picture
99
- </button >
100
+ <button @click =" signOut(auth)" >SignOut</button >
101
+ <button @click =" signInAnonymously(auth)" >Anonymous signIn</button >
102
+ <button @click =" signinPopup()" >Signin Google (popup)</button >
103
+ <button @click =" signinRedirect()" >Signin Google (redirect)</button >
104
+ <button @click =" changeUserImage" >Change User picture</button >
100
105
101
106
<form @submit.prevent =" signUp()" >
102
107
<fieldset >
103
108
<legend >New User</legend >
104
109
105
- <label > Email: <input v-model =" email" type =" email" required > </label >
110
+ <label > Email: <input v-model =" email" type =" email" required / > </label >
106
111
107
112
<label >
108
- Password: <input v-model =" password" type =" password" required >
113
+ Password: <input v-model =" password" type =" password" required / >
109
114
</label >
110
115
111
116
<button >Create</button >
@@ -116,26 +121,26 @@ onMounted(() => {
116
121
<fieldset >
117
122
<legend >Sign in</legend >
118
123
119
- <label > Email: <input v-model =" email" type =" email" required > </label >
124
+ <label > Email: <input v-model =" email" type =" email" required / > </label >
120
125
121
126
<label >
122
- Password: <input v-model =" password" type =" password" required >
127
+ Password: <input v-model =" password" type =" password" required / >
123
128
</label >
124
129
125
130
<button >Signin</button >
126
131
</fieldset >
127
132
</form >
128
133
129
134
<p v-if =" user" >
130
- Name: {{ user.displayName }} <br >
135
+ Name: {{ user.displayName }} <br / >
131
136
<img
132
137
v-if =" user.photoURL"
133
138
:src =" user.photoURL"
134
139
referrerpolicy =" no-referrer"
135
- >
140
+ / >
136
141
</p >
137
142
138
- <hr >
143
+ <hr / >
139
144
140
145
<!-- this is for debug purposes only, displaying it on the server would create a hydration mismatch -->
141
146
<ClientOnly >
0 commit comments