How to logout user using javascript?

Created on 11 April 2018, over 6 years ago
Updated 3 July 2023, over 1 year ago

I am trying to log out using react . When i use following code to log out

axios.post('http://my-lando-app.lndo.site/user/logout?_format=json', {
    'csrf_token':  this.state.csrf_token,
    'logout_token' : this.state.logout_token,
    'Content-type': 'application/json'
})

I get error {"message":"\u0027csrf_token\u0027 URL query argument is missing."}

if i use get request instead of post i get following error

{"message":"\u0027csrf_token\u0027 URL query argument is invalid."}

What will be the right way to logout using javascript? Any working code example will be helpful.

πŸ’¬ Support request
Status

Active

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States adityaj

Live updates comments and jobs are added and updated live.
  • Needs documentation

    A documentation change is requested elsewhere. For Drupal core (and possibly other projects), once the change has been committed, this status should be recorded in a change record node.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΌπŸ‡ΈSamoa ainsofs

    I found this page after having similar problems but after reviewing this page β†’ I found my issue. I am using a different subdomain for front and back ends.

    I was missing

    withCredentials: true

    in the header. You need to have that for BOTH login and logout calls

    You also need

    supportsCredentials: true

    In your services.yml file

Production build 0.71.5 2024