0.8.1 • Published 9 months ago

@prestashopcorp/vue-auth v0.8.1

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

Getting Started

Add dependencies to your project.

pnpm add @prestashopcorp/vue-auth

Then use the plugin after the router initialization.

import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";

import { createPrestashopAuth } from "@prestashopcorp/vue-auth";

import "./assets/main.css";

const app = createApp(App);
const auth = createPrestashopAuth(router);

app.use(auth);
app.use(router);

app.mount("#app");

Configuration

There are several options available with the vue package

Config PropertyDescriptionDefault Value
authorityOIDC Server URLhttps://oauth.prestashop.com/
client_idYour application client Id
scopeAllowed for scopes for your applicationopenid offline_access

Example

createPrestashopAuth(router, {
  authority: 'https://oauth-preprod.prestashop.com/',
  client_id: 'auth-code-client',
  scope: 'openid offline_access',
  extraQueryParams: {
    audience: 'https://accounts-api.distribution.prestashop.net',
  },
})

Usage

This package provide a way to authenticate user without managing the flow with the callback handling.

API

API is available as typings exported by the package.

Example

Using Injection

<template>
  <button v-if="user" @click="$auth.logout">Logout</button>
  <button v-else @click="$auth.login">Login</button>
</template>

<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
  inject: ["$auth"],
  props: {},
  async data() {
    return {
      user: await this.$auth.fetchUser(),
    };
  },
});
</script>

Using composable

<template>
  <button v-if="user" @click="$auth.logout">Logout</button>
  <button v-else @click="$auth.login">Login</button>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { useAuth } from "@prestashopcorp/vue-auth";

export default defineComponent({
  props: {},
  async data() {
    const auth = useAuth()

    return {
      user: await auth.fetchUser(),
    };
  },
});
</script>
0.8.1

9 months ago

0.8.0

1 year ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.0

3 years ago

0.3.2

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago