Skip to content

Commit

Permalink
ssr validCookie
Browse files Browse the repository at this point in the history
  • Loading branch information
jona799t committed Nov 15, 2023
1 parent 1f7bc24 commit 39d59f7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/routes/+layout.server.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { Redirect } from '@sveltejs/kit';

async function validCookie(base64Cookie) {
const cookies = await JSON.parse(await Buffer.from(base64Cookie, 'base64'));
const skoleId = cookies[await (await cookies.map(cookie => cookie.name)).indexOf('LastLoginExamno')].value;
const response = await fetch(`https://www.lectio.dk/lectio/${skoleId}/help/mainhelp.aspx`, { headers: { cookie: await (await cookies.map(cookie => `${cookie.name}=${cookie.value}`)).join('; ') } });

if ((await response.text()).split('Log ud').length > 1) return true;
return false;
}

/** @type {import('./$types').LayoutServerLoad} */
export async function load({ cookies, url }) {
// check cookies to check if user is logged in
// if not, redirect to /login

return {};
}

1 comment on commit 39d59f7

@victorDigital
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG
Nice

Please sign in to comment.