Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Elias177's avatar

API reqeust with Auth

Hey, i use vue and axois to create a api request to my controller to get the data i need, but there is a problem. I dont know how i can send the Auth data or any tokens to auth. (I use Steam Auth)

My Request: axios.get('api/employee/towyard').then((res) => { console.log(res.data) })

The controller auth check:

public function __construct() { $this->middleware('auth'); }

0 likes
10 replies
Elias177's avatar

@willvincent Yes i use this already. Now i want to send a api get request whit axois to the controller when a specific site is loaded and get some data of this, but i want to allow the API request only auth user (checked by the "auth" middleware). Do you understand what i mean ?

Elias177's avatar

@jaseofspades88 Yes but how do I send this data with my axois get query so that only someone who is logged in with the Steam account has access to it ?

jaseofspades88's avatar

What have you actually tried? It's easier for us to help with examples. Show us code samples, clearly wrapped code and simple questions

jaseofspades88's avatar

Markdown... back ticks for wrapping code ``` <- these are back ticks

Elias177's avatar

@jaseofspades88

Api request:

axios.get('api/employee/towyard').then((res) => {
                console.log(res.data)
            })

Controller:

    public function __construct() {
        $this->middleware('auth');
    }

    public function get() {

        $towyards = Towyard::where('status', 'standing')->orWhere('status', 'waiting')->orderBy('server')->orderBy('created_at', 'desc')->get();

        return new Response($towyards, Response::HTTP_OK);
    }

So now i have the problem with the "auth" middleware, because idk how i can send auth data with axois (steam auth)

jaseofspades88's avatar

@Elias177 are you authenticated at this point or do you have an endpoint for authenticating? Is this 'api' endpoint going to be used purely from inside your application?

Elias177's avatar

@jaseofspades88 When the axois query is made the user is authenticated. The request goes to the api.php and from there to the controller. However, I do not know how to transmit the auth data (steam) with axois

Please or to participate in this conversation.