|
| 1 | +<script setup lang="ts"> |
| 2 | +const toast = useToast() |
| 3 | +const profile = useProfile() |
| 4 | +
|
| 5 | +async function signOut() { |
| 6 | + const BE = import.meta.env.VITE_BE_URL |
| 7 | +
|
| 8 | + const response = await fetch(`${BE}/api/auth/logout`, { |
| 9 | + method: 'POST', |
| 10 | + credentials: 'include', |
| 11 | + }) |
| 12 | +
|
| 13 | + const body = await response.json() |
| 14 | +
|
| 15 | + return { |
| 16 | + status: response.status, |
| 17 | + data: body, |
| 18 | + } |
| 19 | +} |
| 20 | +
|
| 21 | +async function handleSignOut() { |
| 22 | + toast.add({ |
| 23 | + title: 'Signing out!', |
| 24 | + color: 'orange', |
| 25 | + icon: 'mingcute:alert-line', |
| 26 | + timeout: 2000, |
| 27 | + }) |
| 28 | + const res = await signOut() |
| 29 | + if (res.status !== 200) { |
| 30 | + toast.add({ |
| 31 | + title: 'Failed to sign out!', |
| 32 | + color: 'red', |
| 33 | + icon: 'mingcute:alert-line', |
| 34 | + timeout: 2000, |
| 35 | + }) |
| 36 | + return |
| 37 | + } |
| 38 | + profile.reset() |
| 39 | + navigateTo('/') |
| 40 | + toast.add({ |
| 41 | + title: 'Signed out!', |
| 42 | + color: 'green', |
| 43 | + icon: 'heroicons:check-circle', |
| 44 | + timeout: 2000, |
| 45 | + }) |
| 46 | +} |
| 47 | +
|
| 48 | +const items = [ |
| 49 | + [{ |
| 50 | + label: `${profile.name}`, |
| 51 | + slot: 'account', |
| 52 | + disabled: true, |
| 53 | + }], |
| 54 | + [{ |
| 55 | + label: 'Your Gists', |
| 56 | + icon: 'heroicons:folder-open', |
| 57 | + }, { |
| 58 | + label: 'Your Stars', |
| 59 | + icon: 'heroicons:folder-open', |
| 60 | + }], |
| 61 | + [{ |
| 62 | + label: 'Status', |
| 63 | + icon: 'i-heroicons-signal', |
| 64 | + }, { |
| 65 | + label: 'Settings', |
| 66 | + icon: 'i-heroicons-cog-8-tooth', |
| 67 | + }], |
| 68 | + [{ |
| 69 | + label: 'Sign out', |
| 70 | + icon: 'i-heroicons-arrow-left-on-rectangle', |
| 71 | + onClick: handleSignOut, |
| 72 | + }], |
| 73 | +] |
| 74 | +</script> |
| 75 | + |
| 76 | +<template> |
| 77 | + <div class="h-12 w-full border flex flex-row align-middle items-center justify-between px-5 overflow-x-hidden"> |
| 78 | + <div> |
| 79 | + <h1 class="text-2xl font-bold text-gray-900 dark:text-white"> |
| 80 | + CodeFlick |
| 81 | + </h1> |
| 82 | + </div> |
| 83 | + <div class="flex flex-row items-center h-full "> |
| 84 | + <UDropdown :items="items" :ui="{ item: { disabled: 'cursor-text select-text' } }" :popper="{ placement: 'bottom-start' }" class="bg-inherit"> |
| 85 | + <Icon name="iconoir:profile-circle" class="text-green-500 w-7 h-7" /> |
| 86 | + <template #account="{ item }"> |
| 87 | + <div class="text-left"> |
| 88 | + Signed in as <strong>{{ item.label }}</strong> |
| 89 | + </div> |
| 90 | + </template> |
| 91 | + |
| 92 | + <template #item="{ item }"> |
| 93 | + <div :onclick="item.onClick" class="w-full flex flex-row justify-between "> |
| 94 | + <span class="truncate">{{ item.label }}</span> |
| 95 | + |
| 96 | + <UIcon :name="item.icon" class="flex-shrink-0 h-4 w-4 text-gray-400 dark:text-gray-500 ms-auto" /> |
| 97 | + </div> |
| 98 | + </template> |
| 99 | + </UDropdown> |
| 100 | + <div class="pt-1"> |
| 101 | + <Theme /> |
| 102 | + </div> |
| 103 | + </div> |
| 104 | + </div> |
| 105 | +</template> |
0 commit comments