Here's how you do auth with 100% SSR in Next.js

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

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

  • @Amankhan-cl1dq
    @Amankhan-cl1dq 2 месяца назад +4

    You are a maniac for not choosing typescript.

  • @AjaySingh-jz8qx
    @AjaySingh-jz8qx 5 месяцев назад +12

    Please also make a video on doing oauth with appwrite in nextjs😊

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

    This was AMAZING Dennis 🎉
    I really needed this!
    You really should do a full course building a SaaS or similar with Appwrite and NextJS. Would gladly pay for that kind of material.

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

      Thank you, I will be working on something like that, hopefully soon 😁 - Dennis Ivy

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

      @@Appwrite yh ithink it would help

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

    Thanks, Definitely needed this!!!
    Been using Appwrite for every projects!
    Need an OAuth in NextJS

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

    Thanks for this Dennis!

    • @Appwrite
      @Appwrite  5 месяцев назад +2

      Realtime with SSR is something I definitely want to cover next. Gonna put that on my to-do list.
      And I used the API route just to show how to protect it. I understand this can be done from the server action. Tutorials often include extra steps just for explanation purposes.
      And I realized I made a mistake with the environment variables after I posted 🤦‍♂️ However, these were only used to initiate a the client and in the API route so all is good. I will make a note and pin it as a comment tho so people are aware of the difference. - Dennis Ivy

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

      @@Appwrite awesome! Yea all good man, just thought I’d flag anyway. Great stuff Dennis! 👌

  • @Coding-Yogi
    @Coding-Yogi 5 месяцев назад

    Awesome work Dennis

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

      Thank you! - Dennis Ivy

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

    Def went with the right thumbnail :) Top was the way to go

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

      I'm doing A/B testing so youtube actually showing both RN.
      Results so far:
      - Top: 56.6%
      - Button: 43.4

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

      @@Appwrite ah cool, didn’t know you could do that on YT! Very cool!

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

      @JonLeeSmith x.com/dennisivy11/status/1818719309113573625?s=46&t=b5FQJ_93_i_9JxrTsD0G4w

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

      @@Appwrite ah missed that on twitter! Cool!

  • @sikandarchishty
    @sikandarchishty 5 месяцев назад +3

    great work, wondering how setting and getting cookies would work with OAuth since OAuth is setting 3-4 cookies when user is logged in?

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

      There is a process to follow. I will have to make a tutorial on this.

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

      @@Appwrite Looking forward to that and thanks for this video :)

  • @RajanVerma-u3u
    @RajanVerma-u3u 8 дней назад +1

    Why do we need to create a new client instance of Appwrite client every time we call createSessionClient or createAdminClient ??

    • @Appwrite
      @Appwrite  7 дней назад

      Because our server is stateless. In a SPA, we can initialize this once on the first request. With SSR, this has to be done on each request. This is standard with any session management system. - Dennis Ivy

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

    Perfect, really excellent thank you

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

    i there an video to do the same auth operations like login logout too in client side appwrite at Account level ?

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

    Dennis, you're amazing! Is it possible to get session() from client component when we store session in cookie? Thank you

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

    I'm experiencing weird behaviour with my middleware when i login using oAuth2. A session is created and the user is redirected to the /account route (the session is logged out in console). In my middleware file, the session does't exist and i'm given a "No Session" error (even when there is a session). Consequently the user is immediately redirected back to /login. This is only happening with oAuth2, my email authentication works fine. Any ideas why this could be happening?

  • @JeandeDieuHAGENIMANA-g3f
    @JeandeDieuHAGENIMANA-g3f 4 месяца назад

    I tried to implement this on my project with typescript but it seems not to work, it is throwing much errors related to server actions

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

    Amazing 🔥🔥

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

    How we can make validation ?
    I don't get it.
    We should to prepare endpoints in our api or sth?

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

    Thanks for the video!
    I have a question. Is there a good way to use the session cookie on the client side too? I set the cookie after login using the "cookies-next" library so that it is also available on the client.
    This only works if I remove the "httpOnly" flag in the setCookie function.
    I guess there is a security issue with removing this, am I right? Do you have any other solutions?

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

    what is your icon theme?

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

    Would love to see a similar video with JWT token authentication with refresh token. Have always struggled with this topic

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

      Appwrite JWT are short lived (15 min), in cases like this you would be better off going with session auth. Or maybe you are refering to JWT's in general, not with NextJS?

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

    How would you handle login errors ?

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

    54:47 nie do końca rozumiem jak to ma działać towrzysz nową sesję aby ją zaraz usunąć. Czy to jest jedynie pobieranie aktualnej sesji.
    Bo jeśli tworzy się nowa sesja to to nie ma sensu.
    Czy ktoś może mi to wytłumaczyć?
    Bo na chwilę obecną wydaje mi się że:
    Scenariusz 1:
    przy logowaniu tworzymy sesję nazwijmy ją sesja1
    oraz przy wylogowywaniu tworzymy sesję nazwijmy ją sesja2
    i za chwilę usówamy sesja2 z naszej listy sesji.
    Scenariusz 2: (chyba ten prawdziwy przynajmniej tak wynika z filmu):
    przy logowaniu tworzymy sesję nazwijmy ją sesja1
    oraz przy wylogowywaniu chcemy stworzyć sesję ale że jest już ona to po prostu zwraca nam sesja1
    i za chwilę usówamy tą sesję po prostu.

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

      You are only creating a session when you login.
      const session = account.createEmailPasswordSession(....)
      On subsequent requests, you are retrieving the session to create a client instance, NOT a session.
      The client is how we interact with our Appwrite backend. So we must first ensure we have a client before we can send a request to our backend, like deleting a session. In a single page application we would only need to create this client instance once and reuse it. However, with SSR, we are loading a new page each time so we need to ensure we always have a new client instance.
      So when we logout, we:
      1. GET the session cookie
      2. Create a client instance
      3. Use the client to delete the session
      Feel free to join our office ours session tomarrow at 9am PST and ask more questions there so I can elaborate. Join our discord server to do so. - Dennis Ivy

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

      Thanks for your great explanation.
      I love appwrite. And the appwrite society. Also your videos ❤

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

    But when the session expires, the user gets logged out, right? Is there something like token refresh for active users?

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

      You can always update the session - Dennis Ivy
      appwrite.io/docs/references/cloud/client-web/account#updateSession

  • @BalintPaladi
    @BalintPaladi 25 дней назад

    Can you make a video of how subscription based contents work? Or if there already is, can somebody get me the link?

  • @Suresh-br2zz
    @Suresh-br2zz 5 месяцев назад

    Nice video!
    Doesn't NEXT_PUBLIC_API_KEY make the api key publicly accessible?

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

      So that was a mistake on my part, however, I only used the environment variables on the server side for my API route and to initial my client, so it's safe either way. However, I will make a note and pin it in this comment section to make sure people are aware of this. Thanks for the heads up :) - Dennis Ivy

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

    ❤ we love your work!. Is it possible to manage the state in ssr??

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

      The idea would be different with SSR so it depends what you are trying to accomplish. If you need to manage the state in a way that handles user interaction on the client side, then you can always just switch to a client-rendered component and do things the traditional react way.

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

    What’s about username/password auth?

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

    How to show a loading indicator when you are waiting the server response on login?

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

      Just add a `loading.js` component in your app folder and create the component you want to see. As simple as that 😁

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

    lack of isomorphic sdk is always a negative in javascript frameworks

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

    Why you use NEXT_PUBLIC in server side ?

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

      So that was a mistake on my part, however, I only used the environment variables on the server side for my API route and to initial my client, so it's safe either way. However, I will make a note and pin it in this comment section to make sure people are aware of this. Thanks for the heads up :) - Dennis Ivy

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

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

    Thank you 👋

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

    I want one feature include that is join other tables like sql

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

      You'll get something soon that will make you happy ;) - Dennis Ivy

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

    Need 2FA and oauth logins as well, and protect pages without making every page dynamic :(

    • @Appwrite
      @Appwrite  2 месяца назад +1

      We have videos on these topics but not with Next js. I can work on some more examples in the future - Dennis Ivy

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

    love from pakistan sir 😘😘🥰🥰 sir now make a full chat web using nextjs appwrite using real time , with notifications , redux or zustand and other best practices , thanks 🥰🥰🥰🥰

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

      Thank you! Appreciate the suggestion :)

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

    middleware denial, hahaha they have to register now, no escape.

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

    feels hacky

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

      We're working on creating some wrappers to simplify this process. The purpose of this video is to get down to the core fundamentals, we'll improve upon this from here :) - Dennis Ivy