Effortless Protected Routes In Next.js Using Middleware

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

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

  • @cesarpizarra1773
    @cesarpizarra1773 2 месяца назад +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  2 месяца назад +1

      Happy it helped!

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

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

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

      You’re welcome!

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

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

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

      You’re welcome!

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

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

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

    So straight forward and easy to understand. Thank you

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

      You’re welcome

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

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

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

      Happy it helped!

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

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

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

      You’re welcome!

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

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

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

      Happy to hear it!

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

    Thank you for such a simple tutorial

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

      You’re welcome

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

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

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

      You’re welcome!

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

    Crazy, so that fixed my JWT authentication protected route problem

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

    Really helpful better than the HOC approach

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

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

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

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

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

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

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

    Super helpful! Thanks for creating this

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

    Thanks. Good feature

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

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

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

      D@mn true, I appreciate ya

    • @habitathomies6049
      @habitathomies6049 18 дней назад

      Legend! I was stuck on this for ages, thanks!

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

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

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

    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 6 месяцев назад

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

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

    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 8 месяцев назад

    Middleware making the routing slower, any solution?

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

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

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

    thnx

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

      You’re welcome

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

    Wonderful🤍