create empty user on first login
the profile creation page doesnt exist yet but its fine
This commit is contained in:
parent
7073483d40
commit
3c09d0947f
17
src/routes/+layout.ts
Normal file
17
src/routes/+layout.ts
Normal 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)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
|
@ -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);
|
||||
};
|
||||
|
|
6
src/routes/profile/create/+page.svelte
Normal file
6
src/routes/profile/create/+page.svelte
Normal 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>
|
Loading…
Reference in a new issue