A
A
Alexander Ampleev2019-04-21 15:30:32
Laravel
Alexander Ampleev, 2019-04-21 15:30:32

How to check on the side of the api method whether the user is authorized if the request goes through ajax in Laravel?

Sample code:

$.ajax({
        async: true,
        cache: false,
        type: "POST",
        url: url,
        dataType: "html",
        ifModified: true,
        timeout: 10000,
        success: function (data) {
        },
        dataFilter: function (data, type) {
            serverData = JSON.parse(data);
            console.log(serverData);
        }
    });

In method
public function like_to_api($type, $id, $value)
    {
        return [Auth::id()];
    }

returns false now

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arthur, 2019-04-21
@Ampleev

https://laravel.com/docs/5.8/api-authentication

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question