🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

vue-auth-sanctum

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

vue-auth-sanctum

A Vue 3 plugin for authentication using Laravel Sanctum.

1.0.0
unpublished
latest
npm
Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

Vue Auth Sanctum

A Vue 3 plugin for authentication using Laravel Sanctum.

Installation

To install the package, run the following command:

  npm install vue-auth-sanctum

Configuration

Add the plugin in your main.ts or main.js file, and provide the required options.

import { createApp } from 'vue';
import App from './App.vue';
import { vueAuthSanctum } from 'vue-auth-sanctum';

const authConfig = {
  apiURL: 'http://localhost:8000',
  mode: 'cookie', // Optional: 'cookie' or 'token'
  endpoints: {
    csrf: '/sanctum/csrf-cookie',
    login: '/login',
    logout: '/logout',
    user: '/api/user',
  },
  csrf: {
    cookie: 'XSRF-TOKEN',
    header: 'X-XSRF-TOKEN',
  }
};

const app = createApp(App);
app.use(vueAuthSanctum, authConfig);
app.mount('#app');

useSanctumAuth

To authenticate a user you should pass the credentials payload as an argument to the login method. The payload should contain all fields required by your Laravel Sanctum backend.

views/Login.vue

  import {ref} from 'vue';
  import { useSanctumAuth } from 'vue-auth-sanctum';

  const { login } = useSanctumAuth();

  const userCredentials = ref({
      email: 'user@mail.com',
      password: '123123',
  });

  await login(userCredentials.value);

useSanctumUser

This composable provides access to the current authenticated user. It supports generic types, so you can get the user as any class you want.

views/Dashboard.vue

  import { useSanctumUser } from 'vue-auth-sanctum';
  
  const user = useSanctumUser();

Keywords

vue

FAQs

Package last updated on 20 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts