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

Issue with auth.ts #23

Open
Loosie94 opened this issue Jun 7, 2023 · 14 comments
Open

Issue with auth.ts #23

Loosie94 opened this issue Jun 7, 2023 · 14 comments

Comments

@Loosie94
Copy link

Loosie94 commented Jun 7, 2023

Hi,

I am facing an issue with the authentication.
When signing in, everything goes fine, but then I later on I get the error:

TypeError: Cannot read properties of undefined (reading 'users')

Seems like it's coming form the function:

async getLoggedinUser() {
      const { $directus } = useNuxtApp();
      try {
        // Try to fetch the user data
        const user = await $directus.users.me.read({
          fields: ['*'],
        });

        // Update the auth store with the user data
        this.loggedIn = true;
        this.user = user;
      } catch (e) {
        console.log(e);
      }
    },

Also, when reloading a page I will have to sign-in again.
This might have to do with the same error?

Hope anyone knows a fix for this.

@bryantgillespie
Copy link
Owner

Well aware there are a few issues with the auth and how cookies are stored. Will have a look at this when I get a bit of time 👍

@BlackDahlia313
Copy link

Well aware there are a few issues with the auth and how cookies are stored. Will have a look at this when I get a bit of time 👍

Hey! The auth.ts is totally fine :)

All that was needed was to import onmounted from vue and than use onmounted to call the user data.

#25

@Loosie94
Copy link
Author

Hi @BlackDahlia313 I tried your pull-request locally, but unfortunately this didn't seem to fix the issue. I am still getting the error and keep signing out.

@M-GRV
Copy link

M-GRV commented Jun 14, 2023

Well aware there are a few issues with the auth and how cookies are stored. Will have a look at this when I get a bit of time 👍

Good to know! I was looking around and it seems onmounted might be the way

Hi @BlackDahlia313 I tried your pull-request locally, but unfortunately this didn't seem to fix the issue. I am still getting the error and keep signing out.

Im assuming you mean for the protected pages using the middleware. That needs an update as well. The patch is only for the auth component. and works when refreshing the homepage to keep you logged in.

The middleware itself needs some love.

@Loosie94
Copy link
Author

Loosie94 commented Jun 15, 2023

@M-GRV How did you fix that? What did you adjust in the middleware/auth.js? Thanks

@BlackDahlia313
Copy link

Exactly how I did it in my PR.

But I am moving onto using a Module now.

@Loosie94
Copy link
Author

Or maybe we can fix this using the new SDK?

@bryantgillespie
Copy link
Owner

I'll probably end up refactoring the Directus plugin and the auth based on the new SDK once released.

@BlackDahlia313
Copy link

Or maybe we can fix this using the new SDK?

thats what we are doing for our site. This starter kit was a good reference to learn from. ;)

@bryantgillespie
Copy link
Owner

Or maybe we can fix this using the new SDK?

thats what we are doing for our site. This starter kit was a good reference to learn from. ;)

Glad to hear it. If you haven't seen it already - there's this Nuxt project we rolled out last week as well to use as reference / inspiration.
https://github.com/directus-community/agency-os

Haven't got a ton of documentation on it yet and will be doing some content around it soon – but it does have a lot of more advanced / interesting bits in there like dynamic forms / dynamic og images / etc.

@dnndev
Copy link

dnndev commented Jul 12, 2023

Really happy to see some new Nuxt examples being developed :)

Looking at the code, is the recommended approach now to use a module for auth?

@Loosie94
Copy link
Author

I have created a pretty large app with this boilerplate, so really happy with that. Only issue for me is the authentication each time I refresh. But will keep an eye out for upcoming changes and the new SDK.

@bryantgillespie
Copy link
Owner

Really happy to see some new Nuxt examples being developed :)

👍

Looking at the code, is the recommended approach now to use a module for auth?

Going to be a bit before I've got time to dig back into this starter, but you might have a look at this module for Nuxt that another community member - @becem-gharbi put together.
https://github.com/becem-gharbi/nuxt-directus

@BlackDahlia313
Copy link

Really happy to see some new Nuxt examples being developed :)

👍

Looking at the code, is the recommended approach now to use a module for auth?

Going to be a bit before I've got time to dig back into this starter, but you might have a look at this module for Nuxt that another community member - @becem-gharbi put together. https://github.com/becem-gharbi/nuxt-directus

Highly recommend this module even tho I decided to build from the SDK directly. The dev is very responsive.

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

5 participants