diff --git a/src/lib/server/ap.js b/src/lib/server/ap.js new file mode 100644 index 0000000..52d1b23 --- /dev/null +++ b/src/lib/server/ap.js @@ -0,0 +1,39 @@ +const loginResponse = { + id: '87bcb6de-bb70-11ee-b719-6756da82e80f', + username: 'hax0r', + acct: 'hax0r', + display_name: 'Jane Doe', + bot: false, + created_at: '2024-01-13T01:23:45.000Z', + note: '
Hackse for life
', + url: 'https://example.com/@hax0r', + avatar: 'https://avatars.example.com/hax0r', + role: { name: 'user' } +}; + +let username = loginResponse.username; + +export const requests = { + get: (url) => { + if (url === '/profile') { + return Promise.resolve({ + ...loginResponse, + username + }); + } + + return Promise.reject(new Error('Unauthorized')); + }, + post: (url, params) => { + if (url === '/login') { + username = params.account; + + return Promise.resolve({ + ...loginResponse, + username: params.account + }); + } + + return Promise.reject(new Error('Invalid Login')); + } +}; diff --git a/src/routes/account/login/+page.server.js b/src/routes/account/login/+page.server.js new file mode 100644 index 0000000..6e4accb --- /dev/null +++ b/src/routes/account/login/+page.server.js @@ -0,0 +1,35 @@ +import { fail, redirect } from '@sveltejs/kit'; + +import { requests } from '$lib/server/ap.js'; + +/** @type {import('./$types').Actions} */ +export const actions = { + login: async ({ cookies, request, url }) => { + const formData = await request.formData(); + const server = formData.get('server'); + const account = formData.get('account'); + const passphrase = formData.get('passphrase'); + + if (!account) { + return fail(400, { account, missing: true }); + } + + if (!passphrase) { + return fail(400, { account, incorrect: true }); + } + + try { + // TODO: Consumre response? + await requests.post('/login', { account, passphrase }); + } catch (exc) { + console.error(exc); + return fail(400, { account, incorrect: true }); + } + + if (url.searchParams.has('redirectTo')) { + redirect(303, url.searchParams.get('redirectTo')); + } + + redirect(303, '/profile'); + } +}; diff --git a/src/routes/account/login/+page.svelte b/src/routes/account/login/+page.svelte index 042a5ac..082e6aa 100644 --- a/src/routes/account/login/+page.svelte +++ b/src/routes/account/login/+page.svelte @@ -1,11 +1,18 @@ + +To use Anvil with your F2 account, fill in your credentials.
-(she/her)
++ No projects added yet. + Add a project + or + import a project. +
+