Skip to content

Commit 1b1cb27

Browse files
committed
Merge branch 'dev' of github.com:hivecom/hivecom.net into dev
2 parents e809b95 + 40b0a9c commit 1b1cb27

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

layouts/default.vue

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff 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>

0 commit comments

Comments
 (0)