Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login success but stuck on root page - user was registered successfully #15

Open
bartonhammond opened this issue Oct 17, 2024 · 14 comments

Comments

@bartonhammond
Copy link

First - thanks for doing this - I'm very impressed (fwtw)

I can register but when I login, w/ no indication of error, it navigates to the root page. I am using this to learn SvelteKit. Is there a route or config file that needs to be updated so that I can view the Profile page for example. I did confirm that PB has the registered user.

@engageintellect
Copy link
Owner

Hey Barton!

Thanks for checking it out. I just tested this by registering a new user and logging in - I was unable to re-created.

Would you mind sharing a screenshot or video of what happens after you log in? You should be redirected back to "/". And see something like this:

Screenshot 2024-10-17 at 3 41 34 PM

From there, you should be able to click the user icon on the right side of the nav to get to your profile page.

@bartonhammond
Copy link
Author

I'm using a password manager but I also did it by hand using the same credentials and it is the same.

Spatz.mov

@engageintellect
Copy link
Owner

engageintellect commented Oct 17, 2024 via email

@bartonhammond
Copy link
Author

Couldn't register

Screenshot 2024-10-17 at 6 17 47 PM

@bartonhammond
Copy link
Author

I attached debugger and see this on login:
Screenshot 2024-10-17 at 6 13 02 PM

@engageintellect
Copy link
Owner

Couldn't register

Screenshot 2024-10-17 at 6 17 47 PM

I have a feeling that you're getting this cause the user is already registered. Try logging on (on spatz url)

As for your local env, did you make sure that your .env file to has the PUBLIC_POCKETBASE_URL pointed at your pocketbase instance? I think it's usually something like "localhost:8090"

@engageintellect
Copy link
Owner

Couldn't register
Screenshot 2024-10-17 at 6 17 47 PM

I have a feeling that you're getting this cause the user is already registered. Try logging on (on spatz url)

As for your local env, did you make sure that your .env file to has the PUBLIC_POCKETBASE_URL pointed at your pocketbase instance? I think it's usually something like "localhost:8090"

Looks like you're already registered:

You should be able to login (on spatz url) with [email protected] and your password.

I'm thinking that your local issue is probably the .env config.

I can have a look at this later this evening to see if there is something I'm missing...

In the meantime, I would recommend trying spatz2, it's more up to date - but shares a lot of the same code. If you can recreate the issue with spatz2 then it's most def a .env config issue.

@bartonhammond
Copy link
Author

ok - I think something maybe out of sync between the registration user/password and the login attempt which would be my fault. Both locally and remote. I'll delete my local user and do all this again. Thanks for slogging through this w/ me.

@engageintellect
Copy link
Owner

ok - I think something maybe out of sync between the registration user/password and the login attempt which would be my fault. Both locally and remote. I'll delete my local user and do all this again. Thanks for slogging through this w/ me.

No problem! Let's get this sorted out and update whatever we need to help future users avoid this issue. We could probably add some better error/feedback on registration and login pages as well.

@bartonhammond
Copy link
Author

entire-step.mov

@engageintellect
Copy link
Owner

Thanks for the recording.

So, your .env must be fine - being that the user is being registered.
And since you're able to register and login on my domain (spatz url), using the same code, I'm still feeling like this is a "dev env" thing.

Let's try this.... replace the contents of /src/hooks.server.ts with this:

import { createInstance } from '$lib/pocketbase';
import type { Handle } from '@sveltejs/kit';
import { dev } from '$app/environment';

export const handle: Handle = async ({ event, resolve }) => {
	const pb = createInstance();

	// load the store data from the request cookie string
	pb.authStore.loadFromCookie(event.request.headers.get('cookie') || '');
	try {
		// get an up-to-date auth store state by verifying and refreshing the loaded auth model (if any)
		if (pb.authStore.isValid) {
			await pb.collection('users').authRefresh();
		}
	} catch (_) {
		// clear the auth store on failed refresh
		pb.authStore.clear();
	}

	event.locals.pb = pb;
	event.locals.user = pb.authStore.model;

	const response = await resolve(event);

	// send back the default 'pb_auth' cookie to the client with the latest store state

	response.headers.set(
		'set-cookie',
		pb.authStore.exportToCookie({ httpOnly: false, sameSite: 'lax', secure: !dev })
	);

	return response;
};

then restart dev env, and see if that helps.

@bartonhammond
Copy link
Author

You asked to try spatz-2' - here is log of command npm install`

[email protected] /Users/bartonhammond/.asdf/installs/nodejs/21.1.0/lib/node_modules/npm
masduende$ npm i 
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/svelte
npm ERR!   dev svelte@"^5.0.0-next.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer svelte@">4.0.0" from @iconify/[email protected]
npm ERR! node_modules/@iconify/svelte
npm ERR!   @iconify/svelte@"^4.0.2" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! 
npm ERR! For a full report see:
npm ERR! /Users/bartonhammond/.npm/_logs/2024-10-18T14_32_34_555Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: /Users/bartonhammond/.npm/_logs/2024-10-18T14_32_34_555Z-debug-0.log

@bartonhammond
Copy link
Author

You asked to replace hooks.server.ts - that worked with spatz - I'll try 2 in bit - need to run

@engageintellect
Copy link
Owner

Right on! Glad we got it sorted.

Would you like to send a PR to update the hooks.server.ts ? If not, I can do it and we can close this issue.

Thanks for pointing this out, it will def help people out in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants