Use Lucia Auth in Client Side - Next 14, Lucia Auth, Typescript

Поделиться
HTML-код
  • Опубликовано: 11 мар 2024
  • In this video I've showed how we can use Lucia Auth in the client side. It's very easy to setup.
    You can give it a like and subscribe to channel if you found this helpful.
    You can find the source code inside this repository, lucia-client-side branch.
    github.com/ugurkellecioglu/ne...

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

  • @codernerd7076
    @codernerd7076 Месяц назад +6

    Don't do this, it will make every single page dynamic, and you will lose the benefits of static rendering, use an API route to check auth...

    • @ugurcodes
      @ugurcodes  Месяц назад +3

      Can you explain a little bit more? I'd like to learn. why would it make other pages dynamic? is it because we pass server components into a client side component?
      If this is your point, that is not how it works. We can pass server components inside client components as children and they will still rendered in the server.
      here you can actually see the source code of the dashboard that is rendered in the server:
      ibb.co/xzzbHbb
      as you can see initial user is there but Client user data is missing it's because it didn't rendered in the server.
      If is there a thing I miss, I'd like to learn more and make a video about it,
      Thanks,
      Ugur

    • @codernerd7076
      @codernerd7076 Месяц назад +2

      @ugurcodes No it makes the page dynamic because you using the cookie function, you can see it if you use the next build command the pages are all rendered dynamic because you're requesting the cookie in the root layout and Next.js will rerender the pages on every request. That is why it's best to use an API route if you need the user info in something like a header and the rest of the page is static content like a front page it's ok for a dashboard. Next dynamic will still render it server-side but it will do it on every request, if that makes sense

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

      @@codernerd7076 Ah, I totally forgot we've used cookies func in validateRequest function. Thank you! I will pin this comment so that people can see it

    • @amelianceskymusic
      @amelianceskymusic 27 дней назад +1

      @@ugurcodes I'm sorry, but what exactly should we do to solve this problem?

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

      @@codernerd7076 can you please explain how to use API route to get cookies? I am searching for this for a long time.

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

    you are killing it on these Lucia videos!

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

      Thanks a ton 🙏 Let me know if you want me to record a video about something you’d like to sed

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

    amazing video

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

    Wow amazing video

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

    Please do a Lucia Facebook OAuth guide 🙏

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

    now some role based protection page :D?

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

      Here you go!
      ruclips.net/video/8A6wTGEyLXE/видео.html

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

    can i use lucia auth with other backend like php, phyton

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

      No, unfortunately you can't. If you are using a framework that supports SSR such as Next JS, you can handle session management inside server side though.
      Then when you make a request to your separate backend (php, python etc.), you could include sessionId as a header and check if this session exists in the database if so continue your operation.

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

      @@ugurcodes oke thanks . how about can we add column like user agent or device id in table session . can we check in api if user agent or device id if not same they can not access 401 Unauthorized in api

  • @nasko235679
    @nasko235679 6 дней назад

    Neither a context provider nor a useEffect is a safe way to implement auth logic. Auth logic on the client is generally a horrible idea. When using something that doesn't work with next middleware like lucia the best solution is to have all protected pages be server components by default and do auth checks there and just import client components inside those server component pages.

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

    there is security issue, someone can still cookies and send scrf request to server then get user data

    • @codelivewithme
      @codelivewithme 2 дня назад

      so we must should do auth in middleware