Compare commits
No commits in common. "46eb892f51b212a057386ad99fc4a1e862d0f005" and "a581480ae1cdf1c5019b42c5c8b57af4b226ce72" have entirely different histories.
46eb892f51
...
a581480ae1
|
@ -1,16 +0,0 @@
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1 +1,6 @@
|
||||||
<p>Hello, World!</p>
|
<p>
|
||||||
|
<a href="/ping">ping</a>
|
||||||
|
<a href="/test">test</a>
|
||||||
|
<a href="/test2">test2</a>
|
||||||
|
<a href="/login">login</a>
|
||||||
|
</p>
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
// src/routes/api/auth/login/+server.ts
|
// src/routes/api/auth/login/+server.ts
|
||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
import { login } from '$lib/api';
|
import { login } from '$lib/api';
|
||||||
import type { PageServerLoad } from '../../../test2/$types';
|
|
||||||
|
|
||||||
export const POST: PageServerLoad = async ({ request, cookies }) => {
|
export async function POST({ request, cookies }) {
|
||||||
console.log("in POST1")
|
console.log("in POST1")
|
||||||
const authToken = request.headers.get('App-Token');
|
const authToken = request.headers.get('App-Token');
|
||||||
console.log("authToken = ", authToken)
|
console.log("authToken = ", authToken)
|
||||||
|
@ -23,7 +22,7 @@ export const POST: PageServerLoad = async ({ request, cookies }) => {
|
||||||
console.log("in POST5")
|
console.log("in POST5")
|
||||||
return json({ id: loginResponse.id, name: loginResponse.name });
|
return json({ id: loginResponse.id, name: loginResponse.name });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return json({ error: error }, { status: 401 });
|
return json({ error: error.message }, { status: 401 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<script>
|
<script>
|
||||||
import { goto } from "$app/navigation";
|
|
||||||
import { addSuccessToast } from "$lib/components/store";
|
import { addSuccessToast } from "$lib/components/store";
|
||||||
import Toasts from "$lib/components/Toasts.svelte";
|
import Toasts from "$lib/components/Toasts.svelte";
|
||||||
let username = $state("");
|
let username = $state("");
|
||||||
|
@ -24,7 +23,8 @@
|
||||||
credentials: "include", // Important to send cookies with requests
|
credentials: "include", // Important to send cookies with requests
|
||||||
});
|
});
|
||||||
addSuccessToast("Login successful!");
|
addSuccessToast("Login successful!");
|
||||||
goto("/");
|
// setToken(resp.token);
|
||||||
|
// goto("/test");
|
||||||
console.log(resp);
|
console.log(resp);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof Error) {
|
if (err instanceof Error) {
|
||||||
|
|
9
src/routes/test2/+page.server.js
Normal file
9
src/routes/test2/+page.server.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
export async function load({ fetch }) {
|
||||||
|
const response = await fetch("https://api.fin.qowevisa.click/api/authping", {
|
||||||
|
credentials: "include",
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: await response.json()
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,9 +0,0 @@
|
||||||
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()
|
|
||||||
};
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user