Skip to content
Advertisement

How to authenticate user without a DB in Laravel?

I created a new project in Laravel that consumes all data from an API. For private data like a user profile, I need an access token to get the data.

Once I have an access token, how do I set the token as Auth::id() in Laravel? Or perhaps I can store the user profile as Auth::user() so that I can use @auth in a frontend blade file?

JavaScript

I tried using Auth::attempt, Auth::login(), and the other method, but all of these required a user table. My project does not have a database.

Advertisement

Answer

You can do something like following.

In the controller

JavaScript

In the view

JavaScript

Hope this helps.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement