0

I normally was using Auth in Laravel blade view to remove buttons that some users have no right too. Now i have just started lately trying to learn Vue and im wondering how im supposed to use this in a Vue Component.

This is what i were using in blade and would like to use in Vue component.

    @if(!Auth::guest() && ($post->author_id == Auth::user()->id))
        <a href="{{ url('home/edit/'.$post->slug)}}" class="btn-sm btn-info">Edit Post</a>
        <a href="{{  url('home/delete/'.$post->id.'?_token='.csrf_token()) }}" class="btn-sm btn-warning">Delete</a>
    @endif

2 Answers 2

1

You can pass the User instance into the component with a prop. For example:

<example-component :user="{{ Auth::user() }}"></example-component>

Then you can access the user's information like so:

<template>

 <p>{{ user.name }}</p>

</template>
export default {
   props : ['user']
}
Sign up to request clarification or add additional context in comments.

Comments

1

There is no way for using default Laravel Auth. You should use special packages for API authentication such as Laravel Sanctum https://laravel.com/docs/8.x/sanctum

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.