File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,25 @@ async function signOut() {
77 await supabase .auth .signOut ()
88 navigateTo (' /login' )
99}
10+
11+ // Listen for auth events and save username
12+ const username = ref ()
13+
14+ supabase .auth .onAuthStateChange ((event , session ) => {
15+ switch (event ) {
16+ case ' SIGNED_IN' : {
17+ if (session ) {
18+ username .value = session .user .user_metadata .username ?? session .user .email
19+ }
20+ break
21+ }
22+
23+ case ' SIGNED_OUT' : {
24+ username .value = ' Not logged in'
25+ break
26+ }
27+ }
28+ })
1029 </script >
1130
1231<template >
@@ -43,9 +62,7 @@ async function signOut() {
4362 <Avatar src =" https://i.imgur.com/65aJ4oG.png" width =" 32" height =" 32" alt =" Username" />
4463 </button >
4564 </template >
46- <DropdownTitle >
47- Username
48- </DropdownTitle >
65+ <DropdownTitle >{{ username }}</DropdownTitle >
4966 <DropdownItem icon =" ph:sign-out" @click =" signOut" >
5067 Sign out
5168 </DropdownItem >
You can’t perform that action at this time.
0 commit comments