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

nipun's avatar
Level 2

Vue3 with Sanctum - Subdomains get unauthenticated even user login successfully.

I'm having an application with 5 different sub-applications where they use multiple sub-domains under one main domain with vue2. Everything working with vue2 implementations. And I'm trying to implement auth UIs (its a separate vue3 project) with the below technologies

  1. Vue 3.2 2.Vue router 4.1 3.Vite 3.0 4.Pinia 2.0

So my applications are like below with vue2

  1. Auth app (localhost:3000)
  2. Profile app (localhost:3001)
  3. Dashboard app (localhost:3002)

At the moment I have implemented all the functionalities related to Auth app with vue3. But I'm having an issue with that. So initial applications will work as follow.

  1. User gets authenticated via auth app and then redirect to Profile app
  2. If the user clicks on the dashboard app link it will redirect the user back to auth app with redirect_uri so that when it redirects to auth app will check auth status and if the user is authenticated then the user will be redirected to the redirect_uri which comes with router query.

At the moment this is working with vue2. But it's not working with vue3.

How does it work with Vue3.

  1. Send a get request to /sanctum/csrf-cookie and then send a post request with email and password.
  2. After successful login redirect the user to the Profile app. (But app says unauthenticated for all requests and it will redirect back to auth app - 3000)

I use the below configurations

import axios from "axios";

  const instance = axios.create({
   withCredentials: true,
   baseURL: import.meta.env.VITE_APP_API_URL,
   headers: {
     Accept: "application/json",
     "Content-Type": "application/json",
     },
  });

If I use Vue 2 auth app then everything works as required.

IF I REFRESH THE PAGE AFTER LOGIN WITHOUT REDIRECTING THE USER TO PROFILE IT WILL SUCCESSFULLY GET THE CURRENT USER. BUT ASS SOON AS I REDIRECT USER TO PROFILE THEN IT SAYS Unauthenticated AND REDIRECT TO LOGIN. AT THIS MOMENT USER IS UNAUTHENTICATED AND NEEDS TO RE-LOGIN.

I have referred so many answers at Laracast and StackOverflow. But wasn't able to find the exact issue. Really appreciate any help on this one.

Thanks

0 likes
0 replies

Please or to participate in this conversation.