0

is there a way to inject axios.get() header into a route request before the controller is accessed.

Please not that a link with the url (/verify) was sent to the users email via api and i want to include the bearer token then the user clicks the url.

This is my route from web.php

    Route::get('/verify-email', [VerifyEmailController::class, '__invoke'])
    ->middleware(['signed', 'throttle:6,1'])
    ->name('verification.verify');

And this is create in a js folder

import axios from 'axios'

axios.create({
  baseURL: '/verify-email',
  headers: {'Bearer Token': 'foobar515615612655'}
});

Danny
  • 15
  • 3
  • axios.create({ baseURL: '/verify-email', headers: {'Bearer': 'foobar515615612655'} }); This should be Bearer instead of Bearer Token if its not working check it with axios.post request with headers: {'Bearer': 'foobar515615612655'} – Manish J Jul 01 '22 at 17:16
  • Does this answer your question? [How to send authorization header with axios](https://stackoverflow.com/questions/44245588/how-to-send-authorization-header-with-axios) – Peppermintology Jul 01 '22 at 17:53
  • 1
    @ManishJ That's not how you send the `authorization` header. `Bearer` is part of the header value, not its key. – Peppermintology Jul 01 '22 at 17:54

1 Answers1

-1

You should add the x-requested-with header with XMLHttpRequest as value.

Checkout the following example:

headers: {
  'Bearer Token': 'foobar515615612655',
  'x-requested-with' : 'XMLHttpRequest'
}
MaartenDev
  • 5,631
  • 5
  • 21
  • 33
HamzaO
  • 37
  • 5