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

MeisamTj's avatar

Token, JWT, Passport or Sanctum ?? Which one is the best for Vue app authentication?

Hi there, Loosing Blade helpers in Vue is a totally nightmare! Which one of these is more useful for Vue app in Laravel?

0 likes
7 replies
devondahon's avatar

I totally agree, it's a real nightmare!

From what I understand, Sanctum is a lighter auth system to be used in your SPA under the same domain as the API like my-spa.home.com and my-api.home.com. Passport allows to sign in from a SPA on another domain like my-spa.com and my-api.com, but the user is redirected to the backend (my-api.com) to login, which is not very user friendly. Token and JWT just seem older and more complicated to manage.

1 like
litvinjuan's avatar

If your SPA is on the same domain as laravel, you can use Sanctum's SPA Authentication.

If it's on a different domain, you can still use Sanctum, but you must check out Sanctum's API Token Authentication.

As of today, if you are creating an SPA -either same or different domain-, I suggest you use Sanctum because it's lightweight and is designed specifically for this use-case. Passport isn't intended to be used for SPA Authentication and thus is not the best fit. Sanctum, token and JWT options are all pretty similar, but sanctum is newer, more robust, and easier to implement in my opinion

Usage

When you sign in a user, create a token for the user and return the plainTextToken.

public function login() {
    // Check credentials
    return $user->createToken('browser')->plainTextToken;
}

You can save that locally and then simply use it in your Authentication header:

"headers": {
    "Authentication": "Bearer {TOKEN}"
}
17 likes
martinbean's avatar

Loosing Blade helpers in Vue is a totally nightmare!

@meisamtj Well, one’s a PHP templating engine and the other is a JavaScript component library.

Which one of these is more useful for Vue app in Laravel?

Impossible to tell without knowing any of your application’s requirements.

3 likes
Quaque's avatar

Hi.. Can I use sanctum API auth for Both mobile app & spa authentication?

1 like
shaher11's avatar

@Quaque Mobile needs token for authentication you can use sanctum or JWT

1 like
martinbean's avatar

@shaher11 …or Passport, which implements OAuth—a well-known standard—and used to authorise many, many mobile applications.

1 like

Please or to participate in this conversation.