-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3660be2
commit f4fee69
Showing
3 changed files
with
52 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script setup lang="ts"> | ||
import { useUserStore } from './stores/userStore'; | ||
const userStore = useUserStore(); | ||
onMounted(async () => { | ||
await userStore.fetchUserData(); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { defineStore } from 'pinia'; | ||
|
||
interface Profile { | ||
id: string; | ||
email: string; | ||
app_email_alias: string; | ||
} | ||
|
||
export const useUserStore = defineStore('user', { | ||
state: () => ({ | ||
id: '', | ||
email: '', | ||
app_email_alias: '', | ||
}), | ||
actions: { | ||
async fetchUserData() { | ||
const config = useRuntimeConfig(); | ||
const apiBase = config.public.apiBase; | ||
const token = useSupabaseSession().value?.access_token; | ||
if (!token) return; | ||
const { data } = await useFetch<Profile>(`${apiBase}/api/me`, { | ||
method: 'GET', | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
if (data.value) { | ||
this.id = data.value.id; | ||
this.email = data.value.email; | ||
this.app_email_alias = data.value.app_email_alias; | ||
} | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters