Code Monkey home page Code Monkey logo

Comments (3)

huy97 avatar huy97 commented on August 28, 2024

Hi @lasha94 ,
First thanks for using my library. I'm really sorry by issue you have, but please check for solution here.
My library using cookie to store a secret key, it default name is _csrf, so your request need auto attach this cookie before sending to server.
With axios you can enable mode withCredentials: true to attach cookie automatically. I have a same solution for angular here.
Finally, let's talk to me if the issue is still unresolved, many thanks

from csrf.

lasha94 avatar lasha94 commented on August 28, 2024

I have already added it. This is my script.

  async getToken() {
    return await firstValueFrom(this.appService.getToken());
  }

  async checkCsrf() {
    const csrfToken = await this.getToken();
    // console.log(csrfToken);
    const resp = await firstValueFrom(this.appService.checkCsrf(csrfToken));
    // console.log(resp);
  }

When i make get request to http://localhost:3000/api/token it doesnt add cookie, and when i make post request im getting {"statusCode":403,"message":"CSRF token not found"} then it adds cookie, and after that im getting this on every request {"statusCode":403,"message":"Invalid CSRF Token"}

from csrf.

lasha94 avatar lasha94 commented on August 28, 2024

I thought it withCredentials: true needed only for post request. I added it to getToken request too and now it works. Thank you. Dependencies need update, package doesnt work on latest nest project.

from csrf.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.