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

this.$http returns promise #23

Open
Blaxzter opened this issue Apr 4, 2024 · 1 comment
Open

this.$http returns promise #23

Blaxzter opened this issue Apr 4, 2024 · 1 comment

Comments

@Blaxzter
Copy link

Blaxzter commented Apr 4, 2024

I'm registering the vue-authenticate-2 plugin like this:

const authenticationOption: AuthenticateOptions = {
  baseUrl: 'http://localhost:8055',
  axios: axios.create({}),
  providers: {},
  // storageType: 'localStorage',
};

app.use(VueAuthenticate, authenticationOption);
app.provide('$auth', app.config.globalProperties.$auth);

And in my component i use:

const $auth = inject('$auth') as VueAuthenticate;

const login = async () => {
  if (!$auth) return;
  await $auth.login({ email: email.value, password: password.value })
};

Well nothing happend and $auth.isAuthenticated stayed false.

After manually linking the source maps and a look into the source code this line:
https://github.com/ajmas/vue-authenticate-2/blob/f81d8270c4d2445db9476f5e7b1dc51bee9d64e2/src/authenticate.js#L146C1-L148C21

returns a promise and hands it into the setToken function.

Any idea what i'm doing wrong?
Or is there just a await missing?
How could this have ever worked?

@gdesoto
Copy link

gdesoto commented Apr 5, 2024

Just started using the library, and I'm seeing the same. Looks line 146 in the blob you found needs to be
const response = await this.$http(requestOptions);

My workaround in the meantime is to also call the setToken() method in my login function after receiving the completed response.

async login(credentials) {
        // ... setup & validation ... //
        const auth_response = await this.$auth.login(credentials);
        this.$auth.setToken(auth_response);
}

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