engageintellect / spatz

An opinionated template for building full-stack Svelte applications ridiculously fast. Includes auth, database, admin panel, user dashboard, themes, icons, and more.
https://spatz.engage-dev.com
MIT License
155 stars 13 forks source link

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

Open bartonhammond opened 2 weeks ago

bartonhammond commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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

https://github.com/user-attachments/assets/2fab88fc-5be4-42e8-99df-5dfa900cd439

engageintellect commented 2 weeks ago

Thanks for this. Can you re-create at https://spatz.engage-dev.com ?Are you getting any output in the server or browser consoles?Do pocketbase logs in the admin dashboard show the attempted request?I have a feeling this could be unique to your dev environment… I’m trying to think of a way I could recreate this locally. 🤔 Sent from my iPhoneOn Oct 17, 2024, at 4:04 PM, Barton Hammond @.***> wrote: I'm using a password manager but I also did it by hand using the same credentials and it is the same. https://github.com/user-attachments/assets/2fab88fc-5be4-42e8-99df-5dfa900cd439

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

bartonhammond commented 2 weeks ago

Couldn't register

Screenshot 2024-10-17 at 6 17 47 PM
bartonhammond commented 2 weeks ago

I attached debugger and see this on login:

Screenshot 2024-10-17 at 6 13 02 PM
engageintellect commented 2 weeks ago

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 commented 2 weeks ago

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 buddywhammond@gmail.com 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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

https://github.com/user-attachments/assets/550e4e2b-0223-4c41-ae7a-165ff19645fc

engageintellect commented 2 weeks ago

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 commented 2 weeks ago

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

npm@10.2.0 /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: spatz-2@0.2.6
npm ERR! Found: svelte@5.0.0-next.269
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/svelte@4.0.2
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 commented 2 weeks ago

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

engageintellect commented 2 weeks ago

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.