Answers.Body: <p>You can use <a href="https://craftcms.com/docs/3.x/config/config-settings.html#defaultcookiedomain" rel="nofollow noreferrer"><code>defaultCookieDomain</code> config setting</a> to make all Craft cookies use your root domain:</p>
  <pre><code>// config/general.php
  
  // mind the dot at the start
  'defaultCookieDomain' =&gt; '.mydomain.com',
  </code></pre>
  <p>This ensures that Craft's cookies apply to both the root domain and the subdomain, so the login should persist.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-21T10:04:50.753Z
Answers.Text: Thanks for the response, unfortunately this doesn't work.
  
  After login into the front end form and navigating to the subdomain i am still presented with the craft login screen. fyi i cleared caches and hard reloaded browser etc
Answers.UserDisplayName: Jamie Nuom
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-21T10:25:17.097Z
Answers.Text: @JamieNuom After logging in, can you check the cookies set in your browser? Do they use the correct domain? There are also other possibilities why it's not working. Does axios use the browser's user agent string? Try turning off `requireMatchingUserAgentForSession` and `requireUserAgentAndIpForSession` in the general config.  Maybe try setting `sameSiteCookieValue` to `Lax` to make sure cookies are sent during initial navigation. There are many reasons why the session might not be accepted cross-domain, make sure to check the cookies in your browser and your config to find potential problems.
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-27T16:01:08.600Z
Answers.Text: I've decided to disable headless mode for this project and create a frontend login from within the craft framework rather than on a separate url as the project needs wrapping up and i cant find a time efficient solution.
  
  Thanks for your thoughts on this. I did try what you suggested but to no avail unfortunately
Answers.UserDisplayName: Jamie Nuom
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-27T14:20:55.757Z
Answers.Text: Thanks @MortizLost! That worked. Jamie if you still need this it has to be the other way around.
  Example: Craft -> admin.craft.test
  Front-end -> craft.test and 'defaultCookieDomain' => '.craft.test',
Answers.UserDisplayName: Eduard
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-21T09:20:08.213Z
Answers.LastActivityDate: 2021-07-21T09:20:08.213Z
Answers.UserDisplayName: MoritzLost
Body: <p>Im im using craft as a headless CMS to power a Nuxt frontend.</p>
  <p>I have a situation where i need the user to login on the frontend and then be redirected to a url within the craft CMS admin.</p>
  <p>My question is; how do i persist login from a subdomain (my Nuxt front-end login form) to to the root domain where my CMS admin is located? Or how can i log the user in to the CMS dashboard using the response from an axios login?</p>
  <p><strong>More info:</strong></p>
  <p>Frontend: mydomain.com</p>
  <p>CMS install: my-craft-install.mydomain.com</p>
  <p><strong>Frontend:</strong></p>
  <p>My frontend login form is using axios e.g:</p>
  <pre><code>const data = {
    email,
    password
  };
  const response = await axios.post(&quot;myfrontend.mydomain.com/api/user/login&quot;, qs.stringify(data))
  </code></pre>
  <p><strong>SAML Redirect:</strong></p>
  <p>After successful login the user will be redirected to a url required by the plugin &quot;SAML Identity Provider&quot; which is under the url</p>
  <p><a href="https://my-craft-install.mydomain.com/sso/login/request/%5Bkey%5D" rel="nofollow noreferrer">https://my-craft-install.mydomain.com/sso/login/request/[key]</a></p>
  <p>From here the user will be authenticated by the plugin and redirected again to our 'Brilliant Assessment' sub domain.</p>
  <p>Any help would be greatly appreciated.
  Cheers,
  Jamie</p>
  
Tags: <login><headless><subdomain>
Title: Persist session from frontend login form to craft dashboard on headless install
ThreadText: # Persist session from frontend login form to craft dashboard on headless install
  
  (Asked by: username_0 on 2021-07-21)
  
  Im im using craft as a headless CMS to power a Nuxt frontend.
  
  I have a situation where i need the user to login on the frontend and then be redirected to a url within the craft CMS admin.
  
  My question is; how do i persist login from a subdomain (my Nuxt front-end login form) to to the root domain where my CMS admin is located? Or how can i log the user in to the CMS dashboard using the response from an axios login?
  
  **More info:**
  
  Frontend: mydomain.com
  
  CMS install: my-craft-install.mydomain.com
  
  **Frontend:**
  
  My frontend login form is using axios e.g:
  
  ```
  const data = {
    email,
    password
  };
  const response = await axios.post("myfrontend.mydomain.com/api/user/login", qs.stringify(data))
  
  ```
  
  **SAML Redirect:**
  
  After successful login the user will be redirected to a url required by the plugin "SAML Identity Provider" which is under the url
  
  [https://my-craft-install.mydomain.com/sso/login/request/[key]](https://my-craft-install.mydomain.com/sso/login/request/%5Bkey%5D)
  
  From here the user will be authenticated by the plugin and redirected again to our 'Brilliant Assessment' sub domain.
  
  Any help would be greatly appreciated.
  Cheers,
  username_0
  
  **Tags:** login, headless, subdomain
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-07-21. Score: 1
  
  You can use [`defaultCookieDomain` config setting](https://craftcms.com/docs/3.x/config/config-settings.html#defaultcookiedomain) to make all Craft cookies use your root domain:
  
  ```
  // config/general.php
  
  // mind the dot at the start
  'defaultCookieDomain' => '.mydomain.com',
  
  ```
  
  This ensures that Craft's cookies apply to both the root domain and the subdomain, so the login should persist.
  
  > **Comments:**
  > **username_0**: Thanks for the response, unfortunately this doesn't work.  After login into the front end form and navigating to the subdomain i am still presented with the craft login screen. fyi i cleared caches and hard reloaded browser etc  
  > **username_1**: @username_0 After logging in, can you check the cookies set in your browser? Do they use the correct domain? There are also other possibilities why it's not working. Does axios use the browser's user agent string? Try turning off `requireMatchingUserAgentForSession` and `requireUserAgentAndIpForSession` in the general config.  Maybe try setting `sameSiteCookieValue` to `Lax` to make sure cookies are sent during initial navigation. There are many reasons why the session might not be accepted cross-domain, make sure to check the cookies in your browser and your config to find potential problems.  
  > **username_0**: I've decided to disable headless mode for this project and create a frontend login from within the craft framework rather than on a separate url as the project needs wrapping up and i cant find a time efficient solution.  Thanks for your thoughts on this. I did try what you suggested but to no avail unfortunately  
  > **username_2**: Thanks @MortizLost! That worked. username_0 if you still need this it has to be the other way around. Example: Craft -> admin.craft.test Front-end -> craft.test and 'defaultCookieDomain' => '.craft.test',  
  
  ---
  
  