Skip to content

Invalid CSRF Token

Technical Support
20 11 18.3k 5

Suggested Topics


  • Invalid CSRF token when authenticating via third-party app

    Unsolved Technical Support
    7
    1 Votes
    7 Posts
    3k Views
    S
    @hnipps said in Invalid CSRF token when authenticating via third-party app: I'm trying to use NodeBB as a headless forum (i.e. just a REST API with a separate front end) but keep getting an "invalid csrf token" error when I try to authenticate. I've confirmed I can authenticate via the NodeBB UI on the same instance. I've also tried getting the NodeBB config and using the csrf token from there in my requests but it still does not work. My frontend is a NextJS app that rewrites all /api/:path* requests to http://<MY-NODE-BB-INSTANCE>/api/:path*. It also rewrites the auth paths. I can see the requests reach NodeBB but always get "invalid csrf token". I've verified that I can successfully call GET endpoints from my app, e.g. I can get the user list from /api/users. This is a 2 yr old thread, but @hnipps have you gone any further with the React/NextJS frontend with a headless nodebb? If you have made any progress I would love to contribute on the frontend build. It is daunting to start as a new project but if any foundations were laid I would love to jump in and build upon it.
  • 0 Votes
    7 Posts
    2k Views
    T
    Problem solved Thank you everyone who responded. I have tried everything I could think of, and when nothing worked, I decided to go over the setup, line by line, word by word and that's when I found it! It was a typo in configuration of my nginx, i.e., my own mistake. The following entries were wrong: proxy_set_header X-Forward-For ... proxy_set_header X-Forward-Proto ... They should be X-Forwarded-For and X-Forwarded-Proto, notice they were missing ed in the word forward !
  • Invalid csrf token and Failed login attemp

    Technical Support
    3
    0 Votes
    3 Posts
    1k Views
    N
    Yes, it is same. But error is still there.
  • invalid csrf token & forbidden login errors

    Moved Technical Support
    2
    0 Votes
    2 Posts
    3k Views
    julianJ
    Ah, yes, that is potentially a stumbling block... port property is optional, if not specified, NodeBB will listen on port 4567. However the url property is the one that is referenced by NodeBB, and is used as the canonical reference to itself... so when somebody asks your forum what it is to be called, NodeBB will respond back with the value in url, so the port is required if you are accessing your forum with port number in url.
  • Again about "invalid csrf token"

    Technical Support
    13
    0 Votes
    13 Posts
    6k Views
    S
    @julian thanks!

Looks like your connection to NodeBB Community was lost, please wait while we try to reconnect.