penambahan route protection
This commit is contained in:
@@ -1,13 +1,44 @@
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import { writable } from "svelte/store";
|
||||
import Sidebar from "../../components/Sidebar.svelte";
|
||||
import { onMount } from "svelte";
|
||||
import { supabase } from "$lib/supabaseClient";
|
||||
import { goto } from "$app/navigation";
|
||||
import type { Session } from "@supabase/supabase-js";
|
||||
|
||||
export let data;
|
||||
|
||||
let notifications = 3; // Contoh jumlah notifikasi
|
||||
let notifications = 3;
|
||||
let user = {
|
||||
name: "John Doe",
|
||||
avatar: "https://i.pravatar.cc/40", // Avatar placeholder
|
||||
avatar: "https://i.pravatar.cc/40",
|
||||
};
|
||||
let userdata: any = null;
|
||||
|
||||
const session = writable<Session | null>(null);
|
||||
|
||||
onMount(async () => {
|
||||
const {
|
||||
data: { session: currentSession },
|
||||
} = await supabase.auth.getSession();
|
||||
|
||||
session.set(currentSession || null);
|
||||
|
||||
supabase.auth.onAuthStateChange((event, sessionValue) => {
|
||||
session.set(sessionValue);
|
||||
if (!sessionValue) goto("/login");
|
||||
});
|
||||
|
||||
const userStr = localStorage.getItem("user");
|
||||
if (userStr) {
|
||||
userdata = JSON.parse(userStr);
|
||||
} else {
|
||||
goto("/login");
|
||||
}
|
||||
|
||||
user.name = userdata.full_name || "Guest";
|
||||
user.avatar = userdata.profile_picture || "https://i.pravatar.cc/40";
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="flex h-screen">
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { supabase } from "$lib/supabaseClient";
|
||||
import { redirect } from "@sveltejs/kit";
|
||||
|
||||
export const load = async (event) => {
|
||||
if (!event.locals.user){
|
||||
import type { RequestEvent } from "@sveltejs/kit";
|
||||
|
||||
export const load = async (event: RequestEvent & { locals: { user?: any } }) => {
|
||||
|
||||
if (!event.locals.user) {
|
||||
console.log(event.url)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -90,7 +90,6 @@
|
||||
{ label: "Guest", value: "Guest" },
|
||||
];
|
||||
|
||||
|
||||
let currentUserId: string | null = null;
|
||||
|
||||
onMount(async () => {
|
||||
@@ -226,8 +225,6 @@
|
||||
: issue.approval
|
||||
? "APPROVED"
|
||||
: "REJECTED", // or map as needed
|
||||
approved_by: issue.approved_by ?? null,
|
||||
approved_date: issue.approved_date ? new Date(issue.approved_date) : null,
|
||||
total_hours_work:
|
||||
Math.abs(
|
||||
new Date(issue.datetime_out).getTime() -
|
||||
@@ -395,8 +392,8 @@
|
||||
const approved_date = new Date().toISOString();
|
||||
const { error } = await supabase
|
||||
.from("vb_timesheet")
|
||||
.update({
|
||||
approval: status ,
|
||||
.update({
|
||||
approval: status,
|
||||
approved_by,
|
||||
approved_date,
|
||||
})
|
||||
@@ -721,7 +718,9 @@
|
||||
>Select Villa</option
|
||||
>
|
||||
{#each dataVilla as villa}
|
||||
<option value={villa.id}>{villa.villa_name}</option>
|
||||
<option value={villa.id}
|
||||
>{villa.villa_name}</option
|
||||
>
|
||||
{/each}
|
||||
</select>
|
||||
{#if $formErrors[col.key]}
|
||||
|
||||
Reference in New Issue
Block a user