create empty user on first login

the profile creation page doesnt exist yet but its fine
This commit is contained in:
Erin 2023-11-12 13:30:05 -05:00
parent 7073483d40
commit 3c09d0947f
3 changed files with 35 additions and 2 deletions

17
src/routes/+layout.ts Normal file
View file

@ -0,0 +1,17 @@
import {redirect} from '@sveltejs/kit';
import type {LayoutLoad} from './$types';
export const load: LayoutLoad = ({data, url}) => {
// logged in (user exists), but username is unset - complete profile first
console.log(data.user);
if (data.user && data.user.name == null) {
// don't redirect forever if we're already on this page
if (url.pathname !== '/profile/create') {
console.log('bad');
throw redirect(
302,
`/profile/create?next=${encodeURIComponent(url.href)}`,
);
}
}
};

View file

@ -89,8 +89,14 @@ export const load: PageServerLoad = async event => {
// if there is not yet anyone registered using this auth method, create a
// new user and a new auth method for that user
let newUser = false;
if (!authMethod) {
throw redirect(302, '/'); // TODO
newUser = true;
const usersRepo = dataSource.getRepository(User);
const user = usersRepo.create({});
await usersRepo.save(user);
authMethod = authMethodsRepo.create({provider, userIdentifier, user});
await authMethodsRepo.save(authMethod);
}
// Create a new auth session for this auth method and save it
@ -104,5 +110,9 @@ export const load: PageServerLoad = async event => {
event.cookies.delete('stateid');
// Woo we did it, redirect on to wherever we were trying to go before
throw redirect(302, '/');
let next = storedState.next;
if (newUser) {
next = `/profile/create?next=${next}`;
}
throw redirect(302, next);
};

View file

@ -0,0 +1,6 @@
<script lang="ts">
// TODO
</script>
<h1>hi yess you need a profile</h1>
<p>i am still learning form shit but. soon</p>