Laravel SPA Authentication - setup and common mistakes

แชร์
ฝัง

ความคิดเห็น • 218

  • @cdruc
    @cdruc  ปีที่แล้ว +6

    Hey! This video is quite old and before axios used to add the x-xsrf-token header automatically. Now it no longer adds it, so you’ll have to do it yourself.
    Laravel Sanctum Auth: masteringauth.com

    • @macarenagd3954
      @macarenagd3954 4 หลายเดือนก่อน

      Hello, your videos help me a lot. I am eagerly looking forward to the launch of your course. How are you doing it now with the new version? I'm using 1.7.2 and can't find a way to avoid getting a 401 error. I´m using withCredentials: true and withXSRFToken: true in my axios configuration. Thanks a lot man!

    • @masollano
      @masollano หลายเดือนก่อน

      is the site already up?

  • @DimZeta
    @DimZeta ปีที่แล้ว +34

    This is one of the clearest and easiest to understand videos about Laravel Sanctum, but also about CORS and CSRF token. Thanks a lot!

    • @cdruc
      @cdruc  ปีที่แล้ว +2

      You’re very welcome! glad you enjoyed it!

    • @teknotips188
      @teknotips188 ปีที่แล้ว

      100% agree

  • @shofada
    @shofada 2 ปีที่แล้ว +15

    Wow! Diagrams and in-depth explanations. This is a sweet upgrade. Thanks for putting this together. Keep it up!

  • @REZAZIMohamedabdessamed
    @REZAZIMohamedabdessamed ปีที่แล้ว +2

    That's the most straight forward and cleaner explanation about Laravel sanctum auth and CORS.

  • @Redheadtama1
    @Redheadtama1 8 หลายเดือนก่อน +2

    Thank you so much for making these videos. After scouring the internet for months looking for help with my hobby project, I have finally found you and you are the only person who explains this stuff in simple terms!
    P.S. I have subscribed to your course. Looking forward to it :)

  • @kapa4208
    @kapa4208 ปีที่แล้ว +3

    Definitely the clearest explanation of SPA authentication with Laravel and Vue. Thank you so much!

  • @IntiMaldonado
    @IntiMaldonado 10 หลายเดือนก่อน +1

    This is the best and most needed explanation online about setting up latavel api with spa front end 👌

  • @kirinyetbrian
    @kirinyetbrian ปีที่แล้ว +2

    This helped me a lot after struggling for three days.Thank you!

  • @sinaahmadpour3180
    @sinaahmadpour3180 11 หลายเดือนก่อน

    After 10 years I finally understood the CORS issue completely!
    Thank you for the great material

    • @cdruc
      @cdruc  11 หลายเดือนก่อน +2

      glad you found it useful! 👊

  • @thisisroushan_1337
    @thisisroushan_1337 6 หลายเดือนก่อน

    This was an incredibly in-depth video that really showed me why I was facing the errors I was facing. Thank you!

  • @janmichaelbesinga3867
    @janmichaelbesinga3867 ปีที่แล้ว +2

    After watching for a couple of minutes, i realized i need to pause the video and hit like and subscribe. Kudos

  • @siyabdev
    @siyabdev 8 หลายเดือนก่อน +1

    Your exaplanation is just WOW

  • @neonneon8225
    @neonneon8225 7 หลายเดือนก่อน +1

    Thank you so much, I resolved the problem I was faced with after watching your great video tutorial. Additionally, I learnt some extra important points from you. Thanks Sir.

  • @ericksanabria5657
    @ericksanabria5657 ปีที่แล้ว +1

    wow! i have been struggling in my first spa project. I wiill reconfigure everything again. You have gained a new subscriber ty

  • @william.darrigo
    @william.darrigo 2 หลายเดือนก่อน

    Super detailed! Best tutorial on sanctum so far. Thank you

  • @ersatztutor
    @ersatztutor ปีที่แล้ว +1

    It took me an embarrassingly long time to figure this out. At the end it was something specific to angulars xsrfmodule.
    Still this video made things clearer!

    • @banalexandru4393
      @banalexandru4393 ปีที่แล้ว

      can you please explain what you did in Angular, my problem is that the xsrf cookie is not being set in the browser when I the request to the /api/csrf-token endpoint...

    • @banalexandru4393
      @banalexandru4393 ปีที่แล้ว +1

      @@ersatztutor sure, i will try tomorrow and will get back to you, thank you!

  • @twentyfirstmen
    @twentyfirstmen ปีที่แล้ว +1

    Bro, You're so good at explaining, Thanks a lot, continue ❤❤💪🏼💪🏼

  • @OnlyGoUpW
    @OnlyGoUpW ปีที่แล้ว +1

    again you saved my life for the second time !
    thank you from algeria !!

  • @youssefelgharib7092
    @youssefelgharib7092 2 ปีที่แล้ว +3

    Thank you very much mr.Constantin Druc for your helpful videos.
    I've a question for you:
    What do you think is more practical inertia or api and why?
    We saw that inertia handles the most annoying things such as CSRF validation, error handling and routing and so on ...

    • @nadjinmalade8738
      @nadjinmalade8738 2 ปีที่แล้ว +1

      Since Inertia came, I only use Inertia.

    • @cdruc
      @cdruc  2 ปีที่แล้ว +1

      As always, it depends on your purpose and what you want to achieve.
      Mobile app in the plans? LaravelAPI + Vue3.
      No mobile app + control over the tech stack? InertiaJS.
      Looking to increase hiring chances? LaravelAPI + Vue3.
      If your aim is speed of development & !mobile, Inertia all the way!

  • @AungThuZaw-u3x
    @AungThuZaw-u3x 8 หลายเดือนก่อน +1

    Thanks A lot. I struggling 2 days for those error.

  • @Naixik
    @Naixik ปีที่แล้ว +2

    Thank you for this vidéo, I lost 2 days to still find your solution !

    • @cdruc
      @cdruc  ปีที่แล้ว

      Glad it helped!

  • @madie2659
    @madie2659 ปีที่แล้ว +1

    wow, you explain very good, please create a video on laravel relationships

    • @cdruc
      @cdruc  ปีที่แล้ว +1

      sadly i’m not working too much with Laravel these days 😩
      look up laracasts - im sure they have something like this for free / on their YT channel 🤞

  • @israeliloba
    @israeliloba 4 หลายเดือนก่อน

    Thank you so much, i have been on this error for two days now

  • @laracrafts195
    @laracrafts195 5 หลายเดือนก่อน

    nice video, you made everything clear and precise without any issues

  • @justinenemuadia9887
    @justinenemuadia9887 ปีที่แล้ว +1

    Man, I came from the article. Thank you soooooooo muchh

  • @tukangkabel4997
    @tukangkabel4997 ปีที่แล้ว

    I like this! Brief explanation, clear and easy to understand.
    I'm waiting for a tutorial on creating or installing an admin template. After login this is done. Thanks

  • @mostafakhaled6680
    @mostafakhaled6680 ปีที่แล้ว +1

    you did a great job man , thanks for your time and efforts

  • @alexalex6163
    @alexalex6163 3 หลายเดือนก่อน +1

    Thank you very much! I`ve learned a lot thanks to you.

  • @turdakhov
    @turdakhov ปีที่แล้ว +1

    Absolutly incredible tutorial. Thank you!

  • @muhammadumarsotvoldiev8768
    @muhammadumarsotvoldiev8768 8 หลายเดือนก่อน +1

    Brilliant job!

  • @Алексей-у6щ1о
    @Алексей-у6щ1о ปีที่แล้ว

    Thank you very much! I could not solve such a problem for a long time.

  • @oketafred
    @oketafred 2 ปีที่แล้ว +1

    Thanks Constantin awesome content as always

    • @cdruc
      @cdruc  2 ปีที่แล้ว

      Glad you enjoyed it👊

  • @pedromartins5512
    @pedromartins5512 ปีที่แล้ว +1

    You saved my project. Thanks 🙏

  • @chalvarenga96
    @chalvarenga96 ปีที่แล้ว +1

    Excellent! I have a question, how can I do everything you did in the video but, instead of testing the endpoints with a frontend, test it with Postman? Is that possible?

  • @LadyMariYo
    @LadyMariYo 2 ปีที่แล้ว +1

    Thank you for the thorough explanation!

  • @randomz-px0
    @randomz-px0 11 หลายเดือนก่อน +1

    THANK FUGGING GOOOD! I almost punched every classmate near me asking questions

  • @johnpaularcenal6516
    @johnpaularcenal6516 11 หลายเดือนก่อน +1

    Saved my life! Thank You so much!!

  • @juniordev4190
    @juniordev4190 2 ปีที่แล้ว +1

    Extremely useful. Thank you for sharing.

    • @cdruc
      @cdruc  2 ปีที่แล้ว

      Glad you find it helpful 👊

  • @dibbyo456
    @dibbyo456 ปีที่แล้ว

    Finally something that actually works. Thank you so much.

    • @cdruc
      @cdruc  ปีที่แล้ว +1

      Glad it helped 👊

  • @rhenaldkarrel
    @rhenaldkarrel ปีที่แล้ว +1

    What if I want to perform a create action where there's a middleware of auth:api? How to pass the token to the axios authorization? Thank you for the video by the way!

    • @JustAnonymous1
      @JustAnonymous1 7 หลายเดือนก่อน

      the same qst did you get it ? i try to passed the toekn in the session and get them before make the req but i don't if it's good solution or not!

  • @ihorrud5088
    @ihorrud5088 ปีที่แล้ว +1

    Thank you bro!Very good explanation.

  • @helioao
    @helioao ปีที่แล้ว

    Jesus! Saved my month! Thank you so much! I spent the last weeks asking WTHGO??? Why this does not work?!??!

    • @cdruc
      @cdruc  ปีที่แล้ว +1

      Glad you found it helpful! 👊

    • @helioao
      @helioao ปีที่แล้ว

      @@cdruc looks like a joke but I came here to stop losing time with a second project, and boo, I inverted the ports of frontend and backend (9001 and 9002). So thanks again.

  • @abdobouna
    @abdobouna 2 ปีที่แล้ว +1

    Very nice video, thank you for the insight.

  • @MichałKrok-x1q
    @MichałKrok-x1q 3 หลายเดือนก่อน

    I followed every step, watched entire video, watched your second video about 419, watched other tutorial and watched other other tutorial, yet i still receive 419 TOKEN MISMATCH. I am done, no idea what is wrong. Anyway, you do quality videos i appreciate that

    • @jgarciascr5
      @jgarciascr5 3 หลายเดือนก่อน

      Same here. I've spent more than one week trying to make my Laravel API work with a very simple React App to register mobile devices in the database. I have even used different versions of Axios (just in case) to no avail. I remember I did it successfully last year with Laravel 10, React 18 and Axios 1.40, but I could not replicate it this year, so I think something has changed that is not allowing me to get and send the secure cookie back to the Server, because I always get the 419 error (CSRF token mismatch). I've noticed that the cookie is already expired when the client App receives it (I don't know why), but I don't know if this is what is triggering the 419 error.

    • @jgarciascr5
      @jgarciascr5 3 หลายเดือนก่อน

      @MichałKrok-x1q I have just discovered my problem and it was basically something very stupid and easy to fix: the values of APP_URL and FRONTEND_URL. Please check my reply to the comment pinned by @cdruc. Hope it helps you as well.

  • @7ala9at
    @7ala9at 2 ปีที่แล้ว +1

    thank you, how to check user status , is logged or not

  • @geniygames4620
    @geniygames4620 6 หลายเดือนก่อน

    Thank you for the video! I do everything the same as you, except installing laravel breeze. It does not work for me. Do I need to do anything additional if it works on a local host without breeze?

  • @MuhammadYusuf-tr3xe
    @MuhammadYusuf-tr3xe ปีที่แล้ว

    Thanks for this wonderful video, however in my case, I set up the STATEFUL_DOMAINS correctly in my env yet I still have a 419 error

  • @Samuel.Mwangi
    @Samuel.Mwangi 2 ปีที่แล้ว +1

    Thanks Constantin as always.

  • @ngounthengos
    @ngounthengos ปีที่แล้ว +1

    thank you for your tips.

  • @johnedmersonpizarra9750
    @johnedmersonpizarra9750 ปีที่แล้ว +1

    Thank you so much for this tutorial 😭😭

  • @ricknatanielwalker9669
    @ricknatanielwalker9669 ปีที่แล้ว

    Hi, your tutorial helped me very much, mainly The article you wrote, is so clear. Congrats.
    Well, not everything is as easier as ti looks. Well, the truth is I am getting a CORS error: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
    I set everything up and one and only thing that is different is that I have a standard Laravel application installation. So, in this installation, the 'paths' variable in the cors.php config file remains 'paths' => ['api/*', 'sanctum/csrf-cookie']. When I accept all incoming requests ('paths' => ['*', 'sanctum/csrf-cookie']), I don't get any CORS error. I wouldn't like to mess with this because I don't know what will be the consequences, but I would appreciate help in this situation. What should I do to pass

    • @cdruc
      @cdruc  ปีที่แล้ว +1

      Hey! Glad the video somewhat helped you move the ball further. Would've been great to have specified the request causing the CORS error but I'll guess it's the /login endpoint 😃
      Now, CORS is a security feature that allows you to control what requests the application should accept, and more importantly, from where (who is allowed to talk to my app).
      The paths array is a list of endpoints that accept cross-origin requests (requests that don't originate/come from your application domain).
      Since the /login endpoint is not part of the paths array, it does not accept cross-origin requests, hence you get the CORS error. Same will be true for other endpoints that are not there - for example, /register.
      But what is even more important, is *who* is allowed to talk to your application. I'm referring to the allowed_origins setting. This should be a list of origins that are allowed to make requests to your laravel application - usually just your frontend app.
      I already made a couple of YT videos on this topic and I know sometimes things are not super clear or easy to follow - it's just hard to fit everything in a couple of videos. That's why I'm working on: masteringauth.com
      Let me know how it goes, and if you stumble upon other issues, please send an e-mail at druc@pinsmile.com . I plan on having a "common issues" section in my course that explains and helps people fix their auth issues. Just make sure to include repository links and the .env file so I can to reproduce the issue(s).

    • @ricknatanielwalker9669
      @ricknatanielwalker9669 ปีที่แล้ว

      @@cdruc I figured out that I had to include the endpoints that I want to hit in my path from the frontend. The confusion I was making is that in the official Laravel documentation site they say just for configuring sanctum to authenticate the SPA I would be able to hit endpoint from web.php.
      I'm excited about the course you're making and I was here thinking if I could give you a hand on it. Well, if it is in my domains

  • @kristiyan.zhelyazkov
    @kristiyan.zhelyazkov 2 ปีที่แล้ว +1

    I have one question. How did you run your spa under spa.example.test? For the laravel project I think you use valet but for the vue project?

    • @cdruc
      @cdruc  2 ปีที่แล้ว +2

      I use a build-watch command for vue and a custom valet driver. Might write a blogpost / make a video on this at some point

    • @cdruc
      @cdruc  2 ปีที่แล้ว +1

      ✍️ Wrote a blogpost: cdruc.com/valet-vue

  • @steevenjackson667
    @steevenjackson667 5 หลายเดือนก่อน

    Seriously. Thank you so much!!!

  • @jervi_sir
    @jervi_sir ปีที่แล้ว

    great video,
    is it same case with reactNative.

  • @cirobastosarana8228
    @cirobastosarana8228 ปีที่แล้ว +1

    Muchas gracias, Great video!

  • @wahyunurarizky1911
    @wahyunurarizky1911 2 ปีที่แล้ว +1

    hello mr Druc, i'm your new subscriber. thanks for making great videos

    • @cdruc
      @cdruc  2 ปีที่แล้ว

      Hello, Glad you find them useful!

  • @МихаилМошков-ч3щ
    @МихаилМошков-ч3щ 7 หลายเดือนก่อน

    Ты лучший! You're the best!

  • @yohanlopes1847
    @yohanlopes1847 ปีที่แล้ว

    marvelous video, taught me a lot

  • @banalexandru4393
    @banalexandru4393 ปีที่แล้ว

    In angular I reapted the exact same steps, but the XSRF-TOKEN cookie is not being set in the browser cookies storage, neither the other API cookies. I can't seem to find an answer for this anywhere

  • @imtiazakidarmawan602
    @imtiazakidarmawan602 7 หลายเดือนก่อน

    I tried the same but there is no cookie and session on both the backend and frontend. Any solution ?. Thanks

  • @peterpardo4138
    @peterpardo4138 ปีที่แล้ว +1

    Wow! Thank you for this!

  • @madtin
    @madtin ปีที่แล้ว

    How would you check if there's a valid session in the front end? laravel is always settings the session cookie even if logged out...

  • @bernanribeiro3329
    @bernanribeiro3329 ปีที่แล้ว +1

    When you install breeze it came to everything setup, but is amazing understand on how it work. But actually I came here because I still getting problem regarding this. My login and register is working perfectly, but when I update the user data I am getting this CORS errors : "'Access-Control-Allow-Origin' header is present on the requested resource." Do have any idea why?

  • @salaheddineahansal
    @salaheddineahansal ปีที่แล้ว +1

    Thank you very much ❤🙏

  • @allaghi
    @allaghi 2 ปีที่แล้ว

    I am working on new project using jetstream with inertia, and planning to connect it with mobile app, I am thinking of using passport, we need you advice.

  • @jondoe79
    @jondoe79 2 ปีที่แล้ว +1

    Awesome 😎 as it should be.

  • @ross78it
    @ross78it 10 หลายเดือนก่อน

    Great tutorial, very well done! I followed it .....but in laravel 10 i always get "csrf-token mismatch" error 419 :(....so frustrating. I think I will give up.

    • @cdruc
      @cdruc  10 หลายเดือนก่อน

      thanks! watch more of my videos 😄
      maybe this one: th-cam.com/video/NY9yoqoN72w/w-d-xo.html and this one th-cam.com/video/HLPoKz9j9KY/w-d-xo.html can help

    • @vitaliipyrih6881
      @vitaliipyrih6881 10 หลายเดือนก่อน +1

      Need to add axios.defaults.withXSRFToken = true;

  • @phenomenal3873
    @phenomenal3873 5 หลายเดือนก่อน

    you are a lifesaver

  • @bulentguven4662
    @bulentguven4662 ปีที่แล้ว

    Hi, I wonder that to I have to clear top level domain cookies every time user logout? For the first time, it is okey that my sanctum api block unregistered user access to the specific url. However, after logging in and logging out again, that's when the problems occur. After logging out, sanctum doesn't block the request and send the success response.

  • @ajndlajjnl4175
    @ajndlajjnl4175 ปีที่แล้ว

    hello sir why dont u use laravel fortify for backend, or develop with inertia for fullstackapp

  • @NguyenVuAnhKhoa
    @NguyenVuAnhKhoa 6 หลายเดือนก่อน

    i got 401 unauthorized but with nuxtjs, i used the loginWith for login and have properly configured but still got that 401 error. Do u have any solution please

  • @dandybagusprasetyo8871
    @dandybagusprasetyo8871 หลายเดือนก่อน

    Hello...
    how can i handle check this user logged in or not? for accessing the requiresAuth: true route in vue js?

  • @godofbrowser
    @godofbrowser ปีที่แล้ว +1

    Thanks for sharing

  • @alimosbah
    @alimosbah 2 ปีที่แล้ว

    Can you explain to deploy laravel vite inertia ssr

  • @tomatomov9061
    @tomatomov9061 ปีที่แล้ว

    Have a question.
    Everytime when the user logs in, sanctum will generate new baerer token and then you are adding it in cookie so it can be used in further actions, until the user logs out ? Did I understand it correct ?

  • @habeebmurtala7318
    @habeebmurtala7318 ปีที่แล้ว

    Hi, thank you for this video. can I authenticate from a mobile app after configuring for spa?

    • @cdruc
      @cdruc  ปีที่แล้ว

      Yes, watch this video:
      tallpad.com/series/laravel-misc/lessons/authenticate-mobile-applications-with-laravel-sanctum
      You don't have to follow all the steps there, though; since you've already configured for spa.

  • @yukngide
    @yukngide 8 หลายเดือนก่อน

    Thank you for the tutorial

  • @firassebai8592
    @firassebai8592 ปีที่แล้ว

    can i start with laravel ui and implement sanctum for spa ?

  • @siyabdev
    @siyabdev 8 หลายเดือนก่อน

    I i set up Cookie based authentication in Laravel/Nuxt/Sanctum and in future, i build a mobile app for my API, the flow of CSRF would remain the same or would it change?

  • @hashemim
    @hashemim ปีที่แล้ว +1

    how can we connect local vue app to a laravel app that deployed on host ?
    thanks for good video btw :)

    • @cdruc
      @cdruc  ปีที่แล้ว

      For dev-only, you can add token based auth and save it in localstorage 🤷‍♂️ - but this is a no-no for production apps.

    • @hashemim
      @hashemim ปีที่แล้ว

      yes i did so. after failure in use token-based auth on shared host i came for this video and it didn't work at first. CPanel delete Authorization Header BTW and my problem was about that ...
      thank you for content 🙏@@cdruc

  • @ibilalkhilji
    @ibilalkhilji ปีที่แล้ว

    Which font you are using in the IDE?

  • @mibrahim4245
    @mibrahim4245 11 หลายเดือนก่อน

    thank you for the very clear video ! ..
    excuse me for the dumb questiion, but if I want to protect a route with the authentication .. should I set it to ->middleware('auth:sanctum') or ->middleware('auth:api') ?
    the second thing, is at login controller; when I want to return the access_token in a cookie, should I return it like this:
    return response()->json(whatever)->withCookie(cookie("access_token", $token, 60) for example? or is there a setting that will make the token be returned in a cookie out of the box ?

    • @cdruc
      @cdruc  11 หลายเดือนก่อน +1

      Hey, you should be using the "auth:sanctum" middleware. For the second thing, I don't know why you would want to return an access_token as a cookie - sounds like you're mixing token based authentication with session based authentication. Maybe these two videos are helpful:
      - th-cam.com/video/NY9yoqoN72w/w-d-xo.html
      - th-cam.com/video/HLPoKz9j9KY/w-d-xo.html

    • @mibrahim4245
      @mibrahim4245 11 หลายเดือนก่อน

      @@cdruc thank you for ur response, yea I think that too ;P .. I'll check out those vids .. thanks

  • @lyricsremix7884
    @lyricsremix7884 ปีที่แล้ว

    the user gets logged out on brouser page refresh
    im using laravel api + react js
    any soltion ?

  • @OnlyGoUpW
    @OnlyGoUpW ปีที่แล้ว +1

    you saved my life

    • @cdruc
      @cdruc  ปีที่แล้ว +1

      Lol 😂😂
      glad u find it helpful 👊

  • @nicolairomanov9305
    @nicolairomanov9305 2 ปีที่แล้ว +1

    Thank you!

  • @adamshaibu3911
    @adamshaibu3911 8 หลายเดือนก่อน

    @cdruc i install sanctum without breeze. Both domains have the same session and xsrf token, yet 401

    • @cdruc
      @cdruc  8 หลายเดือนก่อน

      check sanctum stateful domains list

  • @joshdevofficial
    @joshdevofficial 7 หลายเดือนก่อน

    Yes definitely SPA and API should ne the same top level domain

  • @milendimitrov6503
    @milendimitrov6503 ปีที่แล้ว

    Very nice video

  • @bahacherni8776
    @bahacherni8776 8 หลายเดือนก่อน

    could you please explain it throw pinia state management

    • @cdruc
      @cdruc  7 หลายเดือนก่อน

      i have a couple of videos on this, look through the chanel

  • @allaboutnaturesound6033
    @allaboutnaturesound6033 ปีที่แล้ว +1

    save my day

  • @rafaelacioly3252
    @rafaelacioly3252 10 หลายเดือนก่อน

    Mine keep returning 303 followed by a 200, any idea how to fix it?

    • @cdruc
      @cdruc  9 หลายเดือนก่อน

      this is a weird one. Never got a 303 response - can you put up a reproduceable repo(s)? I'm always down to help if enough details are provided

  • @maiikkeerruu
    @maiikkeerruu 7 หลายเดือนก่อน

    May i know what os you are using?

  • @nadjinmalade8738
    @nadjinmalade8738 2 ปีที่แล้ว +1

    Thank a Lot.

  • @catalina3873
    @catalina3873 ปีที่แล้ว

    谢谢🙏 I hate the cros 😢😅

  • @waqaransari7274
    @waqaransari7274 ปีที่แล้ว

    The post request giving 419 error how to fix it?
    I follow all steps according to the video.

    • @joemarpalting1469
      @joemarpalting1469 11 หลายเดือนก่อน

      same. any solution?

    • @ya9_47
      @ya9_47 10 หลายเดือนก่อน

      @@joemarpalting1469 update Http/MiddlewareVerifyCsrfToken add /login and api/*

    • @alejandrobonilla1142
      @alejandrobonilla1142 9 หลายเดือนก่อน

      @@joemarpalting1469 add this "axios.defaults.withXSRFToken = true;" in App.vue file. =)

  • @nabeelyousafpasha
    @nabeelyousafpasha ปีที่แล้ว

    Respect from Pakistan

  • @binaryfire
    @binaryfire ปีที่แล้ว

    Tried posting a question a couple of times but it keeps getting removed. Maybe TH-cam is flagging it…. 🤷‍♂️

    • @cdruc
      @cdruc  ปีที่แล้ว

      Whaaat? 😯
      Send me an e-mail (you can find the address in the tallpad.com footer)

    • @binaryfire
      @binaryfire ปีที่แล้ว

      @@cdruc Thanks 😀 Great video btw. I’ll give it one more shot, maybe it’ll work as a reply:
      I have a regular Laravel / Blade app and want to drop a small SPA into one of my pages. I already have a functional API and would rather use that than Inertia. The page with SPA and the API are both on the same domain. I.e /my-account and /api
      Would it be possible to make authenticated API calls from that SPA using Sanctum even though the user logged in using the normal Blade login page?

    • @binaryfire
      @binaryfire ปีที่แล้ว

      @@cdruc I might be overthinking things. If I'm understanding things correctly, Sanctum just needs the laravel_session & XSRF-TOKEN cookies to work. Those are set when you log in via a regular PHP login page anyway, so I should be able to make authenticated REST calls with Axios after logging in normally...?

  • @muhamadabdul9231
    @muhamadabdul9231 ปีที่แล้ว

    Why get unauthenticated after reload page?

    • @madie2659
      @madie2659 ปีที่แล้ว

      you need to set token in local storage so you dont get unauthenticated after reload page

  • @nlveej
    @nlveej ปีที่แล้ว

    how did you made your frontend url to be domain instead of localhost:port?

    • @cdruc
      @cdruc  ปีที่แล้ว

      I use laravel valet. it does that automatically

  • @coder236
    @coder236 ปีที่แล้ว

    i know you said that the request must sit on the same domains, but can't you allow separate domains in the cors? so say i'm using laravel Herd, i have a domain of 'my_domain.test' but my react frontend is sitting on localhost:5173... if i put localhost:5173 into cors settings, can i not send requests?

    • @cdruc
      @cdruc  ปีที่แล้ว +1

      cors has nothing to do with this. the problem are cookies - they cannot be shared across different domains.
      watch this: th-cam.com/video/gKC7yvllsPE/w-d-xo.html

    • @coder236
      @coder236 ปีที่แล้ว +1

      @@cdruc ah awesome thanks for this