DEV Community

loading...
Cover image for SPA Authentication using Laravel Sanctum and Vue.js

SPA Authentication using Laravel Sanctum and Vue.js

Suresh Ramani
I am working on Laravel, Vue.js, React.js ( Learning ), and a little bit familiar with Node.js, Socket.io, and MongoDB. and I am do all stuff on Ubuntu so I familiar with Linux Operating System.
・1 min read

Laravel Sanctum provides a lightweight authentication system relying on Laravel's built-in cookie-based session authentication services.

How Laravel Sanctum works
Before we start blindly mashing away without an understanding of what's happening behind the scenes, let's run over how Sanctum works.

Laravel Sanctum uses Laravel's cookie-based session authentication to authenticate users from your client. Here's the flow.

You request a CSRF cookie from Sanctum on the client, which allows you to make CSRF-protected requests to normal endpoints like / login.
You make a request to the normal Laravel / login endpoint.
Laravel issues a cookie holding the user's session.
Any requests to your API now include this cookie, so your user is authenticated for the lifetime of that session.
In this blog, together we will create a complete register and login feature for a single page application in Vue.js and Laravel Sanctum. We will create separate projects for the frontend (in Vue.js ), and for the backend ( Laravel ), that will interact with one another through a REST API.

https://techvblogs.com/blog/spa-authentication-laravel-sanctum-vuejs

Discussion (0)

Forem Open with the Forem app