how to use cartalyst sentinel permission check in laravel vue spa? - laravel

I am building a SPA with laravel and Vue js. For authentication, I have used cartalyst/sentinel package. I am facing a problem to implement permission check in frontend. In the backend I have checked for the permission with Sentinel::hasAccess() function. But in the frontend, I don't have any idea how can I check for permission. As I am using Vue SPA but they don't provide any helper function for SPA frontend.

You could return an array with all the permissions and save it in your vue state and then to verify a permission you could do the following:
<button v-if="permisions['user.delete']" >delete user</button>

Related

Sanctum not working with subdomain SPA with vue3

i am using sanctum with multiple subdomain dynamically created on user creation but when I am using test.localhost/project_name subdomain sanctum auth not working but when i am using localhost/project_name its working fine. i have added
SESSION_DOMAIN=.localhost
SANCTUM_STATEFUL_DOMAINS=umer.localhost:8000,umer.localhost:3000
but no any solution got. if you have any solution please share with me.

Vue application. How to skip authentication to show some component?

I am working with vue and laravel application. I need to show component without user having to login. At the moment, to view the component(that has safety instructions), user have to login. But Now The component is needed outside meaning no login required to view that specific page. How can I achieve this in vue laravel application?
If your Vue app is under protection of 'auth' middleware, you won't be able to reach it before login. Where you need Vue component use web middleware. But to be able to fetch data by Vue component, you will still need a token protection like Sanctum.

Laravel + Vue restrict access to some api routes

I have laravel 8 backend app, serving as API for frontend using Vue 3
In my routes/api.php I have
Route::post('/teachers', [TeacherController::class, 'index'])->name('teachers');
This will return list of teachers to be used in VueJS.
How do I restrict so that only my VueJS app can access api/teachers ? I successfully hitting the api above using POSTMAN, which I expect it to be failed.
I have laravel sanctum installed, although i'm not so sure whether this is something sanctum can help with.
Thanks

How do I make structure SPA and SSR with Laravel?

I'am using Laravel + Nuxt for current project.
Web app has user pages and admin pages.
user pages are working in Laravel + Nuxt SPA but admin pages should works on pure Laravel SSR.
I dont know how to make project structure.
Thank you in advance.
I found answer in this package
https://github.com/m2sd/nuxt-laravel
Main point is route web.php
It redirects SPA requests to Nuxt router
Admin dashboard router should be extracted into new file(ex. admin.php)
Correct answer is following to above article.

How should I authenticate in SPA using VueJS and Vue Router?

I am building a SPA website with Laravel for back-end and VueJS for front-end. And now I want to authenticate users in my website. So I used Laravel Passport for that. My question is that how should I keep user access token and refresh token in vue to make another requests for authentication required routes? Thanks in advance :)

Resources