Log Out Other Devices on SPA using Laravel Sanctum & Laravel Fortify

Поделиться
HTML-код
  • Опубликовано: 29 сен 2024
  • In this video, we add the ability to log out of other devices or sessions. This is not anything new, this feature has been around in Laravel since 5.6, the difference is that in this video we add this feature to the SPA that uses Laravel Sanctum for authentication.
    🤝 You can support me by giving my videos a 👍 & by subscribing to the channel ✔️
    --- Source Code ---
    Back-End (Laravel): github.com/gge...
    Front-End (Next.JS): github.com/gge...
    -- Laravel Fortify Without Jetstream Series --
    Laravel Fortify Without Jetstream Feature - • Laravel Fortify SPA Au...
    Add Two-Factor Authentication Feature - • How to add Two-Factor ...
    Add User Registration Feature - • How to add User Regist...
    Add Account Profile & Password Updates Feature - • How to add Account Pro...
    Add Password Reset Feature - • How to add Password Re...
    Authenticate Mobile App With Fortify & Sanctum - • How to authenticate Mo...
    Updates to Laravel Fortify - • Updates to the Laravel...

Комментарии • 47

  • @thedavistheory7674
    @thedavistheory7674 5 месяцев назад

    i think to this date laravel team hasn't provided a better solution to the AuthenticateSession Middleware you made, also while doing this course i noticed that sanctum and fortify need a bit more of qol improvements as well better interconnection between laravel default auth and sanctum itself, also i think fortify auth logic shouldn't be that hidden inside the dependency code and it would be good if it would be published as well when it publishes its actions, overall this was a really nice course and it helped me get a good grasp on how fortify and sanctum and in general laravel auth work, so thanks a lot gio!

    • @ProgramWithGio
      @ProgramWithGio  5 месяцев назад

      I have not looked at Fortify or Sanctum for awhile so not sure what updates have been made there. Happy to hear that you liked the video 🙌

  • @ThiagoCruz-e5v
    @ThiagoCruz-e5v Год назад

    great video

  • @realslimsutton8914
    @realslimsutton8914 2 года назад

    Is this workaround still required? It does seem a little nasty so I'm hoping there is a more "official" way of doing this. Googling around at 5am hasn't resulted in me finding anything.
    Thanks for the tutorials though, they're super helpful!

    • @ProgramWithGio
      @ProgramWithGio  2 года назад +2

      I don't think it's that nasty to be honest 🙂. The official way is to use Jetstream. This workaround is for when using Sanctum. I'll see if anything has changed since, at that time that was the only way I could make this work with Sanctum.
      Glad you like the tutorials, thank you 🙌

  • @rosselliot8971
    @rosselliot8971 3 года назад +1

    You're doing really good work here. Most videos about Sanctum don't show how to integrate with Fortify which is important since Sanctum doesn't give us a full auth system. I hope you do a series on tokens as well as integrating a refresh token solution. We can revoke tokens with Sanctum but not use them as a proper auth system. I know Taylor said Sanctum's tokens were inspired by Github's access tokens but her really should have made them true JWTs with refresh capabilities. Anyway, good work. Subscribed.

    • @ProgramWithGio
      @ProgramWithGio  3 года назад

      Thank you, means a lot. I have series on Fortify + Sanctum, check out the playlist. Also have the video on using tokens to authenticate mobile app using Sanctum and Fortify. Let me know if those videos are missing something that I may be able to help with.

    • @ProgramWithGio
      @ProgramWithGio  3 года назад

      Here is the first episode of series with Sanctum and Fortify ruclips.net/video/QYJKp1e71xs/видео.html

    • @rosselliot8971
      @rosselliot8971 3 года назад +1

      @@ProgramWithGio I have seen this playlist and it is why I was thanking you. Very good.

    • @ProgramWithGio
      @ProgramWithGio  3 года назад

      @Ross Elliot got it, thank you. I got confused because you said it was missing fortify implementation, but you meant other videos were missing it 🙂 my bad.

    • @rosselliot8971
      @rosselliot8971 3 года назад

      @@ProgramWithGio As I understand it we really don't need Sanctum if doing cookie-based SPA auth with Fortify. If we don't need tokens, what does Sanctum do for us that we can't do with Fortify only?

  • @thehonestabe
    @thehonestabe Год назад

    This still works like a charm! Thanks for the video!!

  • @azizkhan6120
    @azizkhan6120 2 года назад

    Thanks for the video, how to do it if I have Jetstream already installed?

    • @ProgramWithGio
      @ProgramWithGio  2 года назад

      You're welcome. I believe Jetstream already has this feature. Should be in the docs

  • @umairsaeed5925
    @umairsaeed5925 Год назад

    great video but i am little bit confused how did you get login devices list I can't find any documentation on fortify page

    • @ProgramWithGio
      @ProgramWithGio  Год назад +1

      Thank you. I built that off the recording as stated in the video. It just pulls the records from the sessions table & displays it on the UI, you can check the source.

    • @umairsaeed5925
      @umairsaeed5925 Год назад +1

      @@ProgramWithGio Thank you soo much was not expecting that much fast reply

  • @theProzacGeneration
    @theProzacGeneration 3 года назад

    Is it possible to get the other sessions if using cookie as your session driver?

    • @ProgramWithGio
      @ProgramWithGio  3 года назад

      I haven't tried it with cookie driver so I'm not 100% sure. You can easily test it out, let me know what you find 👍

    • @theProzacGeneration
      @theProzacGeneration 3 года назад

      @@ProgramWithGio Well, using the cookie driver didn't store any session information in the database, so that didn't work (and I'm not quite sure how you would query the session cookie from the backend). Unfortunately, while switching to the database driver DOES populate the database on login, all of my other Sanctum protected routes return a 403. 🤔

    • @theProzacGeneration
      @theProzacGeneration 3 года назад

      @@ProgramWithGio So, the cookie driver is a no-go. The database driver wasn't working for me because I was using uuid's on my user model and the session migration was not set up accordingly. Now everything is good.
      Thank you for the great tutorial!

    • @ProgramWithGio
      @ProgramWithGio  3 года назад +1

      @@theProzacGeneration that's great to hear that you got it working at least with database driver. Good job 👍

  • @radumihaidiaconu
    @radumihaidiaconu 3 года назад

    can you find a method to to this with the redis session driver ? i know it doesn't work by default....

    • @ProgramWithGio
      @ProgramWithGio  3 года назад +1

      Added to the list of ideas for videos 👍

    • @radumihaidiaconu
      @radumihaidiaconu 3 года назад

      @@ProgramWithGio cool thanks bro

    • @radumihaidiaconu
      @radumihaidiaconu 3 года назад

      I searched all the internet but never found an answer :( Maybe u can solve this problem

    • @radumihaidiaconu
      @radumihaidiaconu 3 года назад

      @@ProgramWithGio what I want to do is show sessions like in Jetstream or in this video and logout all devices option

    • @ProgramWithGio
      @ProgramWithGio  3 года назад

      @@radumihaidiaconu have you tried using logoutOtherDevices method to see if it works? I believe that should work regardless of the driver you use.