Compare commits

..

5 Commits

6 changed files with 31 additions and 19 deletions

View File

@ -0,0 +1,16 @@
import { redirect } from "@sveltejs/kit";
import type { LayoutServerLoad } from "./$types";
export const load: LayoutServerLoad = async ({ url, fetch, cookies }) => {
if (url.pathname == "/login") {
return
}
console.log("what?")
const response = await fetch("https://api.fin.qowevisa.click/api/authping");
if (!response.ok) {
cookies.delete('session', { path: "/" })
throw redirect(302, "/login");
}
}

View File

@ -1,6 +1 @@
<p>
<a href="/ping">ping</a>
<a href="/test">test</a>
<a href="/test2">test2</a>
<a href="/login">login</a>
</p>
<p>Hello, World!</p>

View File

@ -1,8 +1,9 @@
// src/routes/api/auth/login/+server.ts
import { json } from '@sveltejs/kit';
import { login } from '$lib/api';
import type { PageServerLoad } from '../../../test2/$types';
export async function POST({ request, cookies }) {
export const POST: PageServerLoad = async ({ request, cookies }) => {
console.log("in POST1")
const authToken = request.headers.get('App-Token');
console.log("authToken = ", authToken)
@ -22,7 +23,7 @@ export async function POST({ request, cookies }) {
console.log("in POST5")
return json({ id: loginResponse.id, name: loginResponse.name });
} catch (error) {
return json({ error: error.message }, { status: 401 });
return json({ error: error }, { status: 401 });
}
}

View File

@ -1,4 +1,5 @@
<script>
import { goto } from "$app/navigation";
import { addSuccessToast } from "$lib/components/store";
import Toasts from "$lib/components/Toasts.svelte";
let username = $state("");
@ -23,8 +24,7 @@
credentials: "include", // Important to send cookies with requests
});
addSuccessToast("Login successful!");
// setToken(resp.token);
// goto("/test");
goto("/");
console.log(resp);
} catch (err) {
if (err instanceof Error) {

View File

@ -1,9 +0,0 @@
export async function load({ fetch }) {
const response = await fetch("https://api.fin.qowevisa.click/api/authping", {
credentials: "include",
});
return {
message: await response.json()
};
}

View File

@ -0,0 +1,9 @@
import type { PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ fetch }) => {
const response = await fetch("https://api.fin.qowevisa.click/api/authping");
return {
message: await response.json()
};
}