-
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
Showing
11 changed files
with
4,543 additions
and
5,521 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 |
---|---|---|
@@ -1,12 +1,28 @@ | ||
<template> | ||
<div> | ||
<NuxtLayout> | ||
<NuxtPage /> | ||
<NuxtPage /> | ||
</NuxtLayout> | ||
<Toaster /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import Toaster from '@/components/ui/toast/Toaster.vue' | ||
import Toaster from "@/components/ui/toast/Toaster.vue"; | ||
import { fetchUser } from "@/lib/fetchUser"; | ||
import { useAuthStore } from "@/store/auth"; | ||
import { ref, onMounted, watch } from "vue"; | ||
const { user, setUser } = useAuthStore(); | ||
onMounted(async () => { | ||
console.log("mounted"); | ||
try { | ||
const userData = await fetchUser(); | ||
setUser(userData); | ||
console.log("fetched", user); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}); | ||
</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,68 @@ | ||
<template> | ||
<div class="w-full h-10 flex"> | ||
<NuxtLink | ||
to="/" | ||
class="text-white gap-1 font-semibold text-2xl pl-5 pt-2 flex flex-row items-center" | ||
><img | ||
src="public/icon-green.png" | ||
class="w-10 h-10" | ||
alt="" | ||
/>Nuxt</NuxtLink | ||
> | ||
<NuxtLink | ||
v-if="!isLoggedIn" | ||
to="/login" | ||
class="text-green-500 font-semibold text-2xl pr-5 pt-2 ml-auto" | ||
>Login</NuxtLink | ||
> | ||
<p | ||
v-if="isLoggedIn" | ||
@click="logout" | ||
class="text-green-500 font-semibold text-2xl pr-5 pt-2 ml-auto hover:cursor-pointer" | ||
> | ||
Logout | ||
</p> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { useAuthStore } from "@/store/auth"; | ||
import { useToast } from "@/components/ui/toast/use-toast"; | ||
const { toast } = useToast(); | ||
const { user, setUser } = useAuthStore(); | ||
const isLoggedIn = computed(() => user !== null); | ||
const logout = async () => { | ||
try { | ||
const res = await fetch("http://localhost:3000/api/logout", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
credentials: "include", | ||
}); | ||
if (res.ok) { | ||
setUser(null); | ||
navigateTo("/login"); | ||
} else { | ||
toast({ | ||
title: "Error", | ||
description: "Failed to logout", | ||
}); | ||
console.error("Failed to logout"); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
toast({ | ||
title: "Error", | ||
description: "Failed to logout", | ||
}); | ||
throw createError({ | ||
statusCode: 500, | ||
message: "Failed to logout", | ||
}); | ||
} | ||
}; | ||
</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,21 @@ | ||
|
||
export async function fetchUser() { | ||
try { | ||
const res = await fetch("http://localhost:3000/api/session", { | ||
method: "GET", | ||
credentials: "include", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
if (res.status === 200) { | ||
const data = await res.json(); | ||
console.log("fetchUser:", data.user) | ||
return data.user | ||
} else { | ||
return null; | ||
} | ||
} catch (e) { | ||
return null; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { type ClassValue, clsx } from 'clsx' | ||
import { twMerge } from 'tailwind-merge' | ||
import { type ClassValue, clsx } from "clsx"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
export function cn(...inputs: ClassValue[]) { | ||
return twMerge(clsx(inputs)) | ||
return twMerge(clsx(inputs)); | ||
} | ||
|
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
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
Oops, something went wrong.