Next.js 14 Authentication Tutorial (Super EASY!)

Поделиться
HTML-код
  • Опубликовано: 6 июл 2024
  • Clerk makes authentication SO EASY! Let's see how to add client-side and server-side authentication to a Next.js 14 application from scratch!
    Try Clerk - clerk.dev/
    Newsletter 🗞 - www.jamesqquick.com/newsletter
    *DISCORD*
    Join the Learn Build Teach Discord Server 💬 - / discord
    Follow me on Twitter 🐦 - / jamesqquick
    Check out the Podcast - compressed.fm/
    Courses - jamesqquick.com/courses
    *QUESTIONS ABOUT MY SETUP*
    Check out my Uses page for my VS Code setup, what recording equipment I use, etc. www.jamesqquick.com/uses
    *TIMESTAMPS*
    00:00 - Intro
    00:30 - Creating a New Next.js 14 Project
    03:45 - Creating a New Next.js Route
    04:15 - Creating an Authenticated Navbar
    06:00 - Setting Up Clerk in Next.js
    09:45 - Displaying User Info from Clerk
    12:45 - Adding Public Routes
    14:30 - Adding a DB with Xata
    19:50 - Saving User Data to Xata with Server Actions
    28:30 - Associating Xata Data with Clerk Users
    34:20 - Customize Sign-in and Sign-up Pages

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

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

    Thank you James!
    I was looking for something like this for a long time. I enjoyed it very much. It didn't take me much long and I hardly had any issues. Keep it up!

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

      So glad this was helpful!

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

    Do you have to use a form to save data to the database? Can I use state from a client component and use that in a useEffect to save data to the database?

  • @user-mq1zn1cn1j
    @user-mq1zn1cn1j 6 месяцев назад

    Great , What font do you use in the vscode ?

  • @user-wz7pw7sp7r
    @user-wz7pw7sp7r 2 месяца назад

    Awesome video and great for my project. Slowly building it out so I will check out more of what you have done! Thanks man!

  • @waleedmumtaz
    @waleedmumtaz 8 месяцев назад +5

    Awesome video, James!
    I recently started tapping into backend development to better understand how it all connects with the frontend since I already have some experience on the frontend. I must say now I have a much clear understanding of how things work overall.
    I found the auth part a bit complicated though. I learned about session cookies and tokens using JWT. Do you think one must always consider using a third-party service such as Clerk for authentication? What could be some of the reasons not using such services and building your own?
    Buy the way, Next.js really confusing me now since their server and client logic are in one file. 😅

    • @JamesQQuick
      @JamesQQuick  7 месяцев назад +1

      Yeah I think third party services are very popular and worth trying out. If you would rather build everything yourself, you can totally do that too. SOme people fear lock-in with 3rd party services. For me, the speed at which I can build stuff is worth it

  • @existentialquest1509
    @existentialquest1509 7 месяцев назад +43

    really fed up of these dev advocates pushing products like clerk as auth solutions - huge lock-in , security risk when company u trust to store the most imp aspect of ur app goes bust etc . Auth is something which is a pain but has to be done the right way

    • @pizzabossxd
      @pizzabossxd 7 месяцев назад +3

      and that’s why Auth.js is 🐐

    • @existentialquest1509
      @existentialquest1509 7 месяцев назад +3

      @@pizzabossxd yeah but it’s in perpetual beta and still no credential - this is why i love laravel and the ecosystem - complete with with user profile , 2 factor , email verification with one command - 2 flavours - most importantly comes with xss checks , rate limiting etc .. I hoping auth js goes this way but who knows

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

      If that works for you that's amazing. Just because you don't like existing products doesn't mean iit doesn't have an audience. these tools exist they benefit enough people. Otherwise, they wouldn't be around

    • @iamvinny
      @iamvinny 5 месяцев назад +4

      Javascript developer are so lazy, they need to pay for everything, setting up a database? forget about it, just pay for vercel. authentication? just pay for clerk. good luck with the bills when the project grows.

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

      If you don't want to do that, then....don't lol I'm not saying this is the only way. It's frustrating when people comment as if they know the only way to do things. @@iamvinny

  • @VincentFulco
    @VincentFulco 7 месяцев назад +2

    very helpful. wrapping head around server actions and passing data. thanks

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

      Yeahh! There's a lot going on. It's a fun learning experience though1

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

    can you use another DB for thid?

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

    What font are you using in vscode

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

    sir, what browser are you using for running localhost:3000

  • @tomaasmonaco
    @tomaasmonaco 7 месяцев назад +1

    Do you really recommend Arc for web development? I mean, how you manage to work with the console, css, etc. all good?

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

      It's chromium based so it all works just as it would in Chrome.

  • @AbnerG787
    @AbnerG787 8 месяцев назад +3

    Absolute gold of a video, I'm trying to do this but with supabase instead of xata. Reading through documentation is slow, but a great learning experience! Also, is it possible to do this with supabase or is xata integrated with clerk in a manner that supabase is not? Thanks!

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

      I don't think xata has any integration with clerk. What James showed was pretty generic database stuff.

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

      @@dipteshchoudhuri awesome, I pulled data from supabase and auth with clerk. I just need to integrate them. Thanks!

    • @JamesQQuick
      @JamesQQuick  7 месяцев назад +2

      Yep! You could definitely do this with Supabase, but Supabase already has auth built in. So, if I was using Supabase, I'd just use it's auth instead of clerk personally

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

    what if I want to place that button to sign in in some site?

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

    Great video James, thanks a lot!

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

    Not very related:) but what extension are you using for the terminal suggestions?

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

    Solid video - thanks James!

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

      So glad you enjoyed it! Any requests for future content?

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

      honestly your Xata and clerk videos have really opened up my interest outside of Supabase - it would be great to see more videos on more advanced Xata features like aggregations, summarization - it could help others see alternative stack options to just NextJS + Supabase
      @@JamesQQuick

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

    You're such a great teacher
    Can you do similair project but add roles to users ?

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

    Hey, may I know how did you style your terminal like that?

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

      That is likely either "oh my bash" or "oh my zsh"!

  • @oniely-zzz
    @oniely-zzz 4 месяца назад +2

    I noticed you have a different browser, what browser are you using?

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

      Its Arc browser

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

    getting error on xata init, i tried installing xata globally and locally but still getting errors

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

    James, thank you!

  • @kellslte
    @kellslte 7 месяцев назад +1

    This is a great tutorial, a solid example of how Next.js handles authentication. I really love this. I have a question/request, could you make one video where you use your own auth pages while relying on next-auth to handle the actual auth? I have a project I am working on and I am finding it difficult to handle the authentication with the backend I am working with.

    • @user-fn1qn5vn4d
      @user-fn1qn5vn4d 6 месяцев назад

      bro i tried so many things with next-auth custom login pages, i managed to get it work for a moment, and after some days, that shit stop working on its own, like, firstly it was working fine, but after some days, whenever i login, it will register the login and put it in session, but when i try to go to the protected pages (protected by next-auth middleware) for some reason they redirect me to login page *AGAIN*, and here is a catch, after i give it a little bit of time, with no changes in code or restarting the server, i was just sitting in my browser, it decide to open the protected page on its own 😑😑😑😑, like why, i console.log the shit out of the application, and everything works fine, but it just dont want me to open those pages for sometime, it be like , come after a minute then ill think about it, like bruh

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

    Thank you James

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

    Thanks, very helpfull!

  • @quamzgraphix9826
    @quamzgraphix9826 7 месяцев назад +3

    Great explanation. Please what browser are you using 😅

  • @Assoehosselaar
    @Assoehosselaar 7 месяцев назад +1

    Great video, and introduction to Clerk and Xeta, never heard of either before ❤ only issue is that filtering the database on the userid is not really secure because its not a database rule denying access when the user is not actually the user but just provides the id

    • @JamesQQuick
      @JamesQQuick  7 месяцев назад +2

      In this case, we aren't taking a user id that's passed in. we are taking the user id from the logged in user from a cookie that can't be changed in frontend javascript. Should be good there!

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

    Awsome content James

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

    Many thanks my friend... I hope this help me to get my first shop as jr developer :)

  • @barakel.israel
    @barakel.israel 5 месяцев назад

    Can you do a tutorial on Clerk Organization and UserRoles whilst still including authentication?

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

    Thank you very much!

  • @devyb-cc
    @devyb-cc 5 месяцев назад

    thank you very much, i am moving to workos btw

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

    What's the browser you start at 1:55?

    • @JamesQQuick
      @JamesQQuick  8 месяцев назад +1

      I’m using arc browser!

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

    Good job!

  • @cryptototalwar2915
    @cryptototalwar2915 6 месяцев назад +2

    I have been trying to find a Nextjs tutorial that uses app router for Auth for 2 days and this was the one i needed. Would be cool if you provided source code for the tutorial but its not necessary either since your videos is so short and comprehensive. Thank You!

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

      Ah great point! Here's the closest project that includes Clerk. It's my recent project Deals for Devs.
      github.com/jamesqquick/developer-black-friday-deals

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

    got a Github link for this?

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

    Thanks!

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

    For some reason my app doesn't redirect the user to the clerk login page...can anyone tell me why? everything in the code looks good

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

      check the clerk documentation. its have update how to works with it

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

    thank you

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

    Please you will have to create a bigger fullstack application using these tools. This is a fantastic tutorial!. Thank you very much.

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

      Great feedback! More to come but I'll be working on a courrse with this. Sign up for my newsletter to stay up to date! jamesqquick.com/newsletter

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

      @@JamesQQuick already signed up!!👍

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

    nice very helpful video sir

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

    Yyeaaaay new video.

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

      Yeahhhh what did you think of Clerk?

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

    This came at a really complicated moment where I was trying to resolve auth on a Next JS site using the app router. If I could give it ten likes, I would! Many thanks, James.

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

    How is there no session code whatsoever in the Tutorial they put out for Next 14? I have auth setup, but I can't find anything anywhere for how to get the session after loggin in lol

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

      What information are you looking for exactly? You should have access to everything you need with the hooks from clerk.

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

      @@JamesQQuick I was just trying to do everything with the Credentials Provider and my database. It looks like Clerk provides a way to get session data without having to wrap the app in a ServerSession. The way I wrapped my other apps in a ServerSession Provider doesn’t seem to work with the updates, so that’s what I was stuck on. I guess I’ll just try using Clerk lol 😂

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

      Holy crap. I see why people recommend just using a third party for auth. I set up clerk and it was SO MUCH EASIER. I can finally just build my app now lol. Great tutorial.

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

      I do still think it’s so weird that in the tutorial the Next JS people published there is zero session handling but with clerk I just don’t have to worry about it haha

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

    Hi, you have a great tutorials. I want a tutorial how to custom login signup with social media like google fb etc with the help of node js as backend. totally custom.

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

    Astro authentication coming next? 🍻😊

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

      Waiting for a more stable/supported tool specifically for Astro. But I also cover basic authenticatin in my Astro courrse :)

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

    que navegador é esse ?

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

      Arc browser - arc.net/

  • @rafi-hidayat
    @rafi-hidayat 7 месяцев назад

    because at 16:40 you censored the xata api key, i think you should also censore your xata api key at 36:05 James 😅

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

      I decided it wasn't worth it and I generated a new one lmao. It was harder to edit because I scrolled on the screen lmaooo

    • @rafi-hidayat
      @rafi-hidayat 7 месяцев назад

      @@JamesQQuick the simple one is always one of the best solution i see 😂

  • @IvanRandomDude
    @IvanRandomDude 8 месяцев назад +3

    I mean, it is always easy when you use paid SaaS products :D

    • @JamesQQuick
      @JamesQQuick  8 месяцев назад +1

      Well that's why they exist no? Also, there is a free tier like all good SaaS products. And it's a hell of a lot better than building it all myself in my opinion

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

      @@JamesQQuick the free tier is pretty generous, it's worth it even if I had to pay anyways because when I did auth for a MERN project with JWTs it was quite complex and time consuming this makes things so easy it is ridiculous

    • @olufuwadavid5064
      @olufuwadavid5064 7 месяцев назад +1

      @@kenscode Just did same and bruh, especially intercepting api requests when the JWTs expire

  • @JoseFlores-ol4cc
    @JoseFlores-ol4cc 8 месяцев назад

    super easy! 38 min video 😂

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

      Lol the basic setup to protect a page takes minutes. We also created a brand new project from scratch and added a db. 100% the auth part is east lol

  • @kekefkekef1
    @kekefkekef1 23 дня назад

    Would be great to add in the title of the video you're using Clerk. It bring confusion while searching for generic authentication without a paid tool

    • @JamesQQuick
      @JamesQQuick  19 дней назад

      There is a free tier in Clerk that is really good. Any specific concerns you have about breaking out of their free tier?

    • @kekefkekef1
      @kekefkekef1 19 дней назад

      @@JamesQQuick Not at all, but it basically you need to take that into account if you plan to build an app which, in that case, might bring more than 10k MAU on the platform. So making sure you mention it might be helpful. And also, we never know if they will keep the same pricing.

    • @JamesQQuick
      @JamesQQuick  19 дней назад +1

      @@kekefkekef1 Gotcha. Yeah I guess I just assume that's a given but definitely doesn't hurt to clarify. Great callout!

  • @shekishral6570
    @shekishral6570 23 дня назад

    I like the tutorial. What I don't quit like about this tutorial that you are using not complete free libraries for authe and db.

    • @JamesQQuick
      @JamesQQuick  19 дней назад +1

      There are free tiers for both. What alternatives would you suggest?

    • @shekishral6570
      @shekishral6570 19 дней назад

      @@JamesQQuick I don't claim to know the nodejs ecosystem. I'm mostly a JavaScript / frontend developer who likes to experiment with other technologies. Recently I wanted to explore the possibilities of how to build a full-stack app with nodejs. I know that the technologies you used also have a free version (up to a certain scalability), but I don't like investing my time learning a technology or making my project dependent on a technology that suddenly requires me to pay a lot (and I'm sure many people share my feeling). Especially when it comes to databases (I admit, authentication is more tricky).

    • @JamesQQuick
      @JamesQQuick  19 дней назад

      @@shekishral6570 Yeah, so you'd be looking more for a "build it from scratch" scenario?

    • @shekishral6570
      @shekishral6570 19 дней назад

      @@JamesQQuick Well, not quite. I wouldn't want to do the authentication from scratch. I'm sure there are good open source libraries for that, and with regard to databases, there are also good database libraries or ORM libraries that do a lot of the work for you. In summary, if you only used open source libraries in the video, it would be a "perfect" presentation/tutorial that combines everything to get a quick project up and running (which is also scalable).

    • @JamesQQuick
      @JamesQQuick  19 дней назад

      @@shekishral6570 Ah ok. Something like next-auth (now auth-js I think). fair points. Thanks again for sharing that feedback!

  • @shakapaker
    @shakapaker 7 месяцев назад +1

    Why RUclipsrs always show how to create auth with auth providers lmao

  • @alexy.3512
    @alexy.3512 6 месяцев назад

    People, please do NOT outsource user management and authN/authZ. Companies like that are serious target to be breached. And it is just a matter of time before this happens.

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

    Who the hell is Clerk? Software developer = copy, paste

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

    bruhhhhh what is going on this is toooo ezi pezi

  • @tochimclaren
    @tochimclaren 7 месяцев назад +1

    Another saas authentication tutorial.

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

    Useless video, unless you use some 'clerk' pkg which is not unified approach, that not what I was actually looking for(

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

    so we didn't learn authentication we learned clerk awfull BS content would not recommend

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

    A tutorial with a paid third party service 👎