•
9 min read
Authenticating local development API with User ID tokens
When developing an API, it is often useful to be able to authenticate as a specific user without having to re-run seeders or go through the login and API token creation process.
Instead we can create a middleware that will allow us to authenticate as a specific user by using the user ID as the API token. We will fetch the given user by the ID and assign a temporary Personal Access Token with all abilities.
The following request will authenticate as the user with ID 1
by passing the ID as the bearer token instead of using the actual API key.
Create a new middleware class using the following code: