88 createUserWithEmailAndPassword ,
99} from ' firebase/auth'
1010import { mdiGoogle , mdiGithub , mdiEmail } from ' @mdi/js'
11+ import type { User as FirebaseUser } from ' firebase/auth'
1112
1213const props = withDefaults (
1314 defineProps <{
@@ -28,12 +29,27 @@ const email = ref('')
2829const password = ref (' ' )
2930const emailError = ref (' ' )
3031
32+ type LoginMethod = ' google' | ' github' | ' email'
33+ const LAST_LOGIN_METHOD_KEY = ' httpsms_last_login_method'
34+ const lastUsedMethod = ref <LoginMethod | null >(null )
35+
36+ onMounted (() => {
37+ try {
38+ const stored = localStorage .getItem (LAST_LOGIN_METHOD_KEY )
39+ if (stored === ' google' || stored === ' github' || stored === ' email' ) {
40+ lastUsedMethod .value = stored
41+ }
42+ } catch (error ) {
43+ console .error (error )
44+ }
45+ })
46+
3147async function signInWithGoogle() {
3248 loading .value = true
3349 try {
3450 const auth = getAuth ()
3551 const result = await signInWithPopup (auth , new GoogleAuthProvider ())
36- onSuccess (result .user )
52+ onSuccess (result .user , ' google ' )
3753 } catch (error : unknown ) {
3854 handleError (error , true )
3955 } finally {
@@ -46,7 +62,7 @@ async function signInWithGithub() {
4662 try {
4763 const auth = getAuth ()
4864 const result = await signInWithPopup (auth , new GithubAuthProvider ())
49- onSuccess (result .user )
65+ onSuccess (result .user , ' github ' )
5066 } catch (error : unknown ) {
5167 handleError (error , true )
5268 } finally {
@@ -73,15 +89,20 @@ async function submitEmail() {
7389 password .value ,
7490 )
7591 }
76- onSuccess (result .user )
92+ onSuccess (result .user , ' email ' )
7793 } catch (error : unknown ) {
7894 handleError (error )
7995 } finally {
8096 loading .value = false
8197 }
8298}
8399
84- function onSuccess(user : unknown ) {
100+ function onSuccess(user : FirebaseUser , method : LoginMethod ) {
101+ try {
102+ localStorage .setItem (LAST_LOGIN_METHOD_KEY , method )
103+ } catch (error ) {
104+ console .error (error )
105+ }
85106 notificationsStore .addNotification ({
86107 message: ' Login successful!' ,
87108 type: ' success' ,
@@ -124,11 +145,21 @@ function handleError(error: unknown, isSocial = false) {
124145 block
125146 color =" white"
126147 size =" large"
127- class =" mb-3"
148+ class =" mb-3 position-relative "
128149 :loading =" loading"
129150 :disabled =" loading"
130151 @click =" signInWithGoogle"
131152 >
153+ <v-chip
154+ v-if =" lastUsedMethod === 'google'"
155+ size =" x-small"
156+ color =" primary"
157+ label
158+ variant =" flat"
159+ class =" position-absolute last-used-chip"
160+ >
161+ Last Used
162+ </v-chip >
132163 <v-icon color =" red" :icon =" mdiGoogle" class =" mr-2" />
133164 Continue with Google
134165 </v-btn >
@@ -138,11 +169,21 @@ function handleError(error: unknown, isSocial = false) {
138169 size =" large"
139170 variant =" flat"
140171 color =" black"
141- class =" mb-3"
172+ class =" mb-3 position-relative "
142173 :loading =" loading"
143174 :disabled =" loading"
144175 @click =" signInWithGithub"
145176 >
177+ <v-chip
178+ v-if =" lastUsedMethod === 'github'"
179+ label
180+ size =" x-small"
181+ color =" primary"
182+ variant =" flat"
183+ class =" position-absolute last-used-chip"
184+ >
185+ Last Used
186+ </v-chip >
146187 <v-icon :icon =" mdiGithub" class =" mr-2" />
147188 Continue with GitHub
148189 </v-btn >
@@ -153,10 +194,20 @@ function handleError(error: unknown, isSocial = false) {
153194 size =" large"
154195 variant =" flat"
155196 color =" red"
156- class =" mb-3"
197+ class =" mb-3 position-relative "
157198 :disabled =" loading"
158199 @click =" showEmailForm = true"
159200 >
201+ <v-chip
202+ v-if =" lastUsedMethod === 'email'"
203+ label
204+ size =" x-small"
205+ color =" primary"
206+ variant =" flat"
207+ class =" position-absolute last-used-chip"
208+ >
209+ Last Used
210+ </v-chip >
160211 <v-icon :icon =" mdiEmail" class =" mr-2" />
161212 Continue with email
162213 </v-btn >
@@ -223,3 +274,11 @@ function handleError(error: unknown, isSocial = false) {
223274 </p >
224275 </div >
225276</template >
277+
278+ <style scoped>
279+ .last-used-chip {
280+ top : -8px ;
281+ left : -8px ;
282+ z-index : 1 ;
283+ }
284+ </style >
0 commit comments