[Question] Bearer Token
Closed this issue · 1 comments
kusman28 commented
Hi @manchenkoff how can I add a bearer token for /api/user
after logging in it will execute that endpoint then I got an Unauthenticated error from the API since I need to pass to token first in the Bearer Token before making the request.
nuxt.config.ts
sanctum: {
baseUrl: 'http://localhost:8000',
mode: 'cookie',
userStateKey: 'sanctum.user.identity',
endpoints: {
csrf: 'http://localhost:8000/sanctum/csrf-cookie',
login: 'http://localhost:8000/api/login',
},
csrf: {
cookie: 'XSRF-TOKEN',
header: 'X-XSRF-TOKEN'
},
redirect: {
onLogin: '/dashboard',
onLogout: '/',
}
},
useAuth.ts
import { FetchError } from 'ofetch';
export const useAuth = () => {
const { login: sanctumLogin } = useSanctumAuth()
const { $toast } = useNuxtApp()
const login = async(args: { email: string, password: string}) => {
await sanctumLogin(args)
.catch((e: FetchError) => {
if (e.response?.status === 401) {
$toast.error(e.response?._data.message, {
// position: 'top-right',
dismissible: true,
pauseOnHover: true
})
}
throw e
})
}
return {
login
}
}
manchenkoff commented
Hey @kusman28, according to your nuxt.config.ts
you are using cookie
mode instead of token
one, please check the module documentation. Feel free to re-open the issue if problem persists.