Effortless Protected Routes In Next.js Using Middleware

Поделиться
HTML-код
  • Опубликовано: 27 дек 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.

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

  • @marie-elizeventer7080
    @marie-elizeventer7080 8 месяцев назад +1

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

  • @yushankkashyap7771
    @yushankkashyap7771 28 дней назад

    Man you are a saver. I have wasted so much time on this and you explained it so well. I was stuck due to middleware being in the app folder. Thank you!😄

  • @cesarpizarra1773
    @cesarpizarra1773 4 месяца назад +4

    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  4 месяца назад +1

      Happy it helped!

  • @sandrotabatadze3768
    @sandrotabatadze3768 3 месяца назад +1

    short and understable! without any unnecessary things! thanks man!!

    • @coderyan
      @coderyan  3 месяца назад

      You’re welcome!

  • @zb2747
    @zb2747 4 месяца назад +2

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

    • @coderyan
      @coderyan  4 месяца назад

      You’re welcome!

  • @samnmeje3486
    @samnmeje3486 9 месяцев назад +2

    So straight forward and easy to understand. Thank you

    • @coderyan
      @coderyan  9 месяцев назад

      You’re welcome

  • @csdevelops7
    @csdevelops7 4 месяца назад +2

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

    • @coderyan
      @coderyan  4 месяца назад +1

      Happy it helped!

  • @MuhamadAzizPrasetyo
    @MuhamadAzizPrasetyo 5 месяцев назад +1

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

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

      Happy to hear it!

  • @joze.rios44
    @joze.rios44 9 месяцев назад +1

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

    • @coderyan
      @coderyan  9 месяцев назад

      You’re welcome!

  • @Alim-yo3sc
    @Alim-yo3sc 5 месяцев назад

    Thank you for such a simple tutorial

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

      You’re welcome

  • @abdilaahimowliud7556
    @abdilaahimowliud7556 15 дней назад

    Thank you so much. Very clean

    • @coderyan
      @coderyan  15 дней назад

      Happy it helped!

  • @AHMED-dl5hn
    @AHMED-dl5hn Месяц назад

    thanks a lot man, simple and efficient

    • @coderyan
      @coderyan  Месяц назад

      Happy it helped!

  • @tigana
    @tigana 6 месяцев назад

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

    • @coderyan
      @coderyan  6 месяцев назад

      You’re welcome!

  • @hankersoree
    @hankersoree 9 месяцев назад +7

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

    • @benjaoliva3383
      @benjaoliva3383 9 месяцев назад

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

    • @thatsalot3577
      @thatsalot3577 8 месяцев назад

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

  • @israelzorzor5805
    @israelzorzor5805 6 месяцев назад +1

    Really helpful better than the HOC approach

  • @fabio9311
    @fabio9311 8 месяцев назад

    Super helpful! Thanks for creating this

  • @mrjessan2343
    @mrjessan2343 7 месяцев назад

    Crazy, so that fixed my JWT authentication protected route problem

  • @tigana
    @tigana 6 месяцев назад +1

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

  • @pritishmendhekar360
    @pritishmendhekar360 Месяц назад

    Thanks very helpful😶‍🌫

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

    Thanks. Good feature

  • @benjamingoller6267
    @benjamingoller6267 9 месяцев назад

    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…

  • @minhaz3193
    @minhaz3193 4 месяца назад

    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

  • @DickyFirmansyah-u9o
    @DickyFirmansyah-u9o 5 месяцев назад

    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

  • @VishalMewada-jq4qk
    @VishalMewada-jq4qk 7 месяцев назад

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

  • @devrano48
    @devrano48 9 месяцев назад

    Middleware making the routing slower, any solution?

  • @ThanHtutZaw3
    @ThanHtutZaw3 11 месяцев назад

    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 ?

  • @adnanrruka5152
    @adnanrruka5152 2 месяца назад

    thnx

    • @coderyan
      @coderyan  2 месяца назад

      You’re welcome

  • @EseosaOsayi
    @EseosaOsayi 3 месяца назад

    Winter is coming, 😂 i spy a game of thrones fan

  • @rithikguleria8278
    @rithikguleria8278 2 месяца назад

    Wonderful🤍