Effortless Protected Routes In Next.js Using Middleware

Поділитися
Вставка
  • Опубліковано 5 вер 2024
  • Github project: github.com/cod...
    In this engaging tutorial, we dive into the world of Next.js to explore the powerful role of middleware in creating secure, protected routes. Tailored for both beginners and seasoned developers, the video offers a concise yet comprehensive guide, demonstrating step-by-step how to implement middleware for route protection in Next.js applications.

КОМЕНТАРІ • 32

  • @cesarpizarra1773
    @cesarpizarra1773 8 днів тому

    Man, thank you for this tutorial! I was stuck for hours trying to figure out why my middleware wasn't working. I had placed the middleware file in the app folder and tried debugging it, but nothing worked. Then, I found your video and learned to place the middleware outside the app folder-and it worked!

    • @coderyan
      @coderyan  8 днів тому +1

      Happy it helped!

  • @zb2747
    @zb2747 26 днів тому +1

    No bs with an example and straight to the point. Thank you!

    • @coderyan
      @coderyan  26 днів тому

      You’re welcome!

  • @MuhamadAzizPrasetyo
    @MuhamadAzizPrasetyo Місяць тому +1

    Thank you so much. Very clean and this is what I needed!

    • @coderyan
      @coderyan  Місяць тому

      Happy to hear it!

  • @csdevelops7
    @csdevelops7 27 днів тому +1

    Thanks for doing this video Ryan. I was stuck on this for 2 days lol

    • @coderyan
      @coderyan  27 днів тому +1

      Happy it helped!

  • @samnmeje3486
    @samnmeje3486 6 місяців тому +2

    So straight forward and easy to understand. Thank you

    • @coderyan
      @coderyan  6 місяців тому

      You’re welcome

  • @tigana
    @tigana 2 місяці тому

    This is a really helpful compliment their docs. Thank you!!

    • @coderyan
      @coderyan  2 місяці тому

      You’re welcome!

  • @Alim-yo3sc
    @Alim-yo3sc Місяць тому

    Thank you for such a simple tutorial

    • @coderyan
      @coderyan  Місяць тому

      You’re welcome

  • @marie-elizeventer7080
    @marie-elizeventer7080 5 місяців тому

    This was just what I needed. Thank you very much. Simple and easy to understand.

  • @RVKAWAAA
    @RVKAWAAA 5 місяців тому +1

    Hey, i like this, so easy to make, thanks bro, greetings from Argentina.

    • @coderyan
      @coderyan  5 місяців тому

      You’re welcome!

  • @hankersoree
    @hankersoree 6 місяців тому +7

    how do i make it dynamic? without changing user manually in middleware

    • @benjaoliva3383
      @benjaoliva3383 5 місяців тому

      export const config = {
      matcher: ['/((?!api|_next/static|_next/image|.*\\.png$).*)']
      };
      With this you can run your middleware on every request

    • @thatsalot3577
      @thatsalot3577 5 місяців тому

      @@benjaoliva3383 he's asking how do you know whether the user is logged in or not

  • @israelzorzor5805
    @israelzorzor5805 2 місяці тому +1

    Really helpful better than the HOC approach

  • @fabio9311
    @fabio9311 4 місяці тому

    Super helpful! Thanks for creating this

  • @mrjessan2343
    @mrjessan2343 3 місяці тому

    Crazy, so that fixed my JWT authentication protected route problem

  • @minhaz3193
    @minhaz3193 Місяць тому

    what if i want to have multiple middleware functions? where would they go since we have only one middlware.js file and one export for config

  • @fillipeamg5877
    @fillipeamg5877 Місяць тому

    Thanks. Good feature

  • @tigana
    @tigana 2 місяці тому

    If you have a src folder, try placing it in there. My middleware didn't run until I did that.

    • @morgan24TH
      @morgan24TH 2 місяці тому

      D@mn true, I appreciate ya

  • @DickyFirmansyah-u9o
    @DickyFirmansyah-u9o 2 місяці тому

    so i have setup my middleware and redirect to login page if its not logged in and after login i setup an encodedOriginUrl to go back to that requested page, but can i check if theres a page exist or not in my apps inside middleware? so the user should not go to login page and after login they found that the page is not found, so i just want the user just directly redirect to not found page and not login page if the page doesnt exist in my apps

  • @benjamingoller6267
    @benjamingoller6267 5 місяців тому

    I am frustrated at the moment. I am using server actions eg for database queries. However, whatever I do, I cannot protect the server function from being accessed from anyone from the client side. The function is in a folder utils alongside app. The can use it from client side but so can anyone! I have looked everywhere, but I cannot seem to find how to handle that…

  • @VishalMewada-jq4qk
    @VishalMewada-jq4qk 3 місяці тому

    but while creating a build the middleware.ts file doesn't work then what will be the solution for that edge case ?

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

    My Cookies are exist in normal api call but when I call 2nd api call in service worker notification FCM , I don't get firebase cookies in Next.js api . Is it cross origin issue ?

  • @devrano48
    @devrano48 5 місяців тому

    Middleware making the routing slower, any solution?