Laravel Sancum - automatic CSRF cookie retrieval

Поділитися
Вставка
  • Опубліковано 16 гру 2024

КОМЕНТАРІ • 13

  • @Vladimir-if1uk
    @Vladimir-if1uk 10 місяців тому +1

    hello! Thanks for awesome video. Previously on laravel sanctum + nuxt 3 auth video we created a useApiFetch composable as a wrapper for usual useFetch. But sometimes we need to use an usual $fetch . How to attach all needed headers , credentials:'include' ans so on using $fetch?

  • @thedavistheory7674
    @thedavistheory7674 10 місяців тому +2

    Hey man btw, some useful information is that in the latest version of axios, withCredentials is not enough, you also have to add withXSRFToken and set it to true, this was because there was some kind of cve that allowed leakage of csrf tokens while using withCredentials, so they added the new property around two months ago

    • @cdruc
      @cdruc  10 місяців тому

      Ah yes! In the past the header was included automatically 🙈
      Sometimes you might **not** want to do that - for example when using axios to talk to third-parties (they end up getting your token).
      In the video somewhere bellow the /sanctum/csrf-cookie request, I'm setting the x-xsrf-token header manually - which is what "withXSRFToken:true" does under the hood.
      Didn't know about the option though, thanks!

    • @thedavistheory7674
      @thedavistheory7674 10 місяців тому

      @@cdruc yeah I didn't know that too, I was creating a new app and setting everything correctly but I was still getting the 419 response, and after long hours of stress I found out about that change within axios lol

    • @cdruc
      @cdruc  10 місяців тому

      @@thedavistheory7674 I went through the same thing and was like "what the hell am I doing wrong?? I swear this used to work" 🤣🤣

  • @IgorOliveira
    @IgorOliveira 8 місяців тому

    I'm experiencing a loop when attempting to implement this Axios interceptor. I'm unsure why, as it appears identical.

  • @maenardaboabo1934
    @maenardaboabo1934 8 місяців тому

    Can you show us how you protect your front-end routes?

    • @cdruc
      @cdruc  8 місяців тому

      yes, protect against what?

    • @maenardaboabo1934
      @maenardaboabo1934 8 місяців тому

      @@cdruc like how you redirect the user to the login page if there's no csrf cookie or you get a 401 response

    • @jondoe79
      @jondoe79 7 місяців тому

      You can create a pinia store and set a watch on a variable let's say authenticated, if watch value if false push login route.

  • @jc0164
    @jc0164 10 місяців тому

    wonderfull !!! you're the best !! :)

  • @OldakdLhc
    @OldakdLhc 10 місяців тому

    Awesome tuto ❤
    I have a question:
    How we switch between account in admin dashboard like platform Google, Microsoft, ect

  • @thisisroushan_1337
    @thisisroushan_1337 8 місяців тому

    what'd be great is if you can make a starter-kit for react (or vue) with laravel breeze api - so we can just use that instead of having to do all this every time :P