Тёмный

NextJS Authentication with Server Actions - Learn to build from scratch! 

Coding with Robby
Подписаться 20 тыс.
Просмотров 12 тыс.
50% 1

Опубликовано:

 

25 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 78   
@codingwithrobby
@codingwithrobby 6 месяцев назад
Do everything in server actions! ❤
@junaid-alyyy
@junaid-alyyy 6 месяцев назад
Hi youtube.com/@codingwithrobby . How to remove cookies if the user session is expired. In my use case, I want to remove cookies instead of redirecting the user. Need your help, if you can reply. Thanks
@codingwithrobby
@codingwithrobby 6 месяцев назад
@@junaid-alyyy cookies().delete('Authorization') This should work fine in middleware or a server action
@junaid-alyyy
@junaid-alyyy 6 месяцев назад
@@codingwithrobby - Thanks for the quick response. It works with a server action but I want to validate the user session using middleware and if the session is expired or invalid then the cookie should be deleted but this deletion isn't possible `cookies().delete('Authorization')` in the middleware.
@韩佳骏
@韩佳骏 4 месяца назад
@@junaid-alyyy I also encountered this problem, what should I do?
@韩佳骏
@韩佳骏 4 месяца назад
import { cookies } from "next/headers"; belongs to the server-side API, but logout is a client-side operation
@summersnow2288
@summersnow2288 5 месяцев назад
I don't understand why do you use api within the action, the whole point of action is to get rid of api?
@RobertBojor
@RobertBojor 6 месяцев назад
Thanks for this! But I do have a question... Wouldn't be easier to just use the server action to do all the work instead of having it offload the work to the API route? Based on my understanding of server actions, when you submit the form and the server action is called, under the hood there's a POST request being made to a hidden route (the server action). Daisy chaining the reuests like this might introduce more lag since two calls are being made, not to mention you have to account for errors in both methods.
@macccu
@macccu 5 месяцев назад
Yeah this tutorial makes no sense. Just a proof that you should not trust any random youtuber for programming knowledge. Soon avg TS code tutorial it's going to be worse than PHP 20 years ago. Type safety is not going to help anyone if people are just going to do stupid things.
@newborn7348
@newborn7348 4 месяца назад
Yeah the whole idea of using a server action is so that you wouldn't need to create an api route for things like this.
@AdejoroRofiatAbimbola
@AdejoroRofiatAbimbola 8 месяцев назад
Straight to the point. Thanks so much
@Ronieyit
@Ronieyit 29 дней назад
bestest tutorial l have come across on Next JS Server Actions and Authentication. Very very easy to understand. thanks to you l now have this well understood 🤩
@dzseroldfabian4574
@dzseroldfabian4574 7 месяцев назад
You are an honest, true hero. Keep it up Chief
@Keifeh.P
@Keifeh.P 6 месяцев назад
Exactly what I was looking for, thank you!
@AndrulisTravel
@AndrulisTravel 7 месяцев назад
Very nice :) So if you have time, the next interesting things are 'Forgot password', sending a verification link when a new user registers, to prevent false registrations, and a Google login option :)
@stefanlemke7858
@stefanlemke7858 5 месяцев назад
Absolutely love the way you are explaining things! Please keep up the great work.
@deanelie7775
@deanelie7775 8 месяцев назад
Glad to see this video on my youtube homepage, thank you for this video. ☺
@desmondcoffie65
@desmondcoffie65 4 месяца назад
awesome video, straight to the point . love the way you signed out with peace
@eternl_sunshine22
@eternl_sunshine22 4 месяца назад
fantastic, i managed to follow you throughout the tutorial even if it did take me a while since i had to figure out using drizzle orm but everything was great! will try to implement jwt refresh tokens now
@divinecharles4102
@divinecharles4102 4 месяца назад
Hey man, have you figured out the refresh token part?
@alexvoid8717
@alexvoid8717 7 месяцев назад
I'm new to server actions and still trying to understand them. Aren't they supposed to be independent of APIs/routes and be able to perform database operations directly within themselves?
@TomislavKimovski
@TomislavKimovski 6 месяцев назад
I was thinking the same when I saw that part. No need for the fetch call to the api endpoint because you are already on the server, just do a db lookup.
@marztianpapi3419
@marztianpapi3419 2 месяца назад
Great video bro!
@2pacrapempire866
@2pacrapempire866 7 месяцев назад
Man thanks a lot. was looking for this. Got it at the right time
@MehranRoham
@MehranRoham 3 месяца назад
Thanks so much Robby, this video helped me a lot
@Lovedeep555
@Lovedeep555 2 месяца назад
Its very straight forward, thanks
@newbiedevtons
@newbiedevtons 4 месяца назад
Very helpful and simple to understand
@dzseroldfabian4574
@dzseroldfabian4574 7 месяцев назад
How to Log out? and how to read user data from cookies?
@w.arajinda2968
@w.arajinda2968 7 месяцев назад
thank to you i can continue my projects,keep it up 👍👍👍👍👍
@kpeople96
@kpeople96 Месяц назад
Love the sound of your keyboard. Can you share a keyboard name and link please?
@Leonavancini
@Leonavancini 3 месяца назад
Thanks for this explanation, I have only one question, how can I add refresh token with this approach? can you give me a hint? thanks in advance
@iteratus
@iteratus 3 месяца назад
Another useful google output: www.google.com/gasearch?q=nextjs%20server%20actions%20bearer%20token%20authorization&source=sh/x/gs/m2/5#ip=1 even though the results are probably not what you're expecting, it points you in the right direction
@faxa22
@faxa22 8 месяцев назад
Hi! Really love your content. In intro to App dev you said that tried creating it with golang from scratch. Can you do a video on this topic?)
@ItachiUchiha-w5h
@ItachiUchiha-w5h 7 месяцев назад
I'm getting a Error:p1001: can't reach database server at `localhost`:`5432` How do I solve it
@codingwithrobby
@codingwithrobby 7 месяцев назад
Do you have Postgres installed locally? You could also just get a database at www.elephantsql.com and use the connection string they give you
@ItachiUchiha-w5h
@ItachiUchiha-w5h 7 месяцев назад
@@codingwithrobby yea that was the problem I solved it thanks..
@tshepokhumako1403
@tshepokhumako1403 6 месяцев назад
You so real. Thanks
@mecobrabo5590
@mecobrabo5590 7 месяцев назад
awesome content. can you explain why you moved all the logic to an route handler when you can keep it in the server actions?
@agusjkdev
@agusjkdev 7 месяцев назад
I'd say he wanted to keep it simple, after all is not that bad
@mecobrabo5590
@mecobrabo5590 7 месяцев назад
@@agusjkdev dont think so, adding one more step (the router handler)
@WebWithWes
@WebWithWes Месяц назад
Okay so I was building an app and I had implemented a similar JWT authentication just like this, but then decided that I should switch to use NextAuth and now I'm facing issues with the client useSession() method and the server session not syncing. Are you deliberately not using NextAuth? Can this be implemented with Nextauth?
@WebWithWes
@WebWithWes Месяц назад
The reason I wanted to switch to NextAuth was to easily integrate SSO with different providers like Google, Azure, e.t.c.
@iuliancarnaru954
@iuliancarnaru954 7 месяцев назад
nice one, helpful information
@muhammadijaz6042
@muhammadijaz6042 2 месяца назад
Please, guide me if possible, How to add subscription based payment method that can be customised to any payment solution available all over the world. Take care.
@the.money.mentor.825
@the.money.mentor.825 4 месяца назад
isnt it a bad idea to store the db connection string in an env variable? it can be accessed on the front end. I'm going to watch this video and put it all in the backend and secure it with a public api key and then only allow calls from a certain ip.
@iteratus
@iteratus 3 месяца назад
.env variables are not accessible by FE per default. So we're fine here
@xiaomaitian
@xiaomaitian 6 месяцев назад
With server actions, does it feel like you don't need route handlers
@alexdin1565
@alexdin1565 2 месяца назад
thanks for this amazing content but the only problem is your server actions are not protected so any one can see because you export them
@cyphermediaschool
@cyphermediaschool 6 месяцев назад
How to protect api no one access , we can access only same origin 😢 in next js 14
@BiteAByte-xy3ek
@BiteAByte-xy3ek 5 месяцев назад
Can you implement "Refresh token" and "Token rotation" to this code? seems to be fun.
@divinecharles4102
@divinecharles4102 4 месяца назад
Hey man, have you figured this out now?
@BiteAByte-xy3ek
@BiteAByte-xy3ek 4 месяца назад
@@divinecharles4102 Yes, I may create a video about it
@MusaRehman-m9o
@MusaRehman-m9o 8 месяцев назад
thanks needed this
2 месяца назад
I liked you video thanks
@smexiking8620
@smexiking8620 7 месяцев назад
Hey robby, which operating system you're using? I sense it's linux but which distro? Thanks
@codingwithrobby
@codingwithrobby 7 месяцев назад
It's MacOS, I use a mac mini
@smexiking8620
@smexiking8620 7 месяцев назад
@@codingwithrobby oh okay! Thanks
@financialwonton
@financialwonton 2 месяца назад
Can you do captcha with google?
@financialwonton
@financialwonton 2 месяца назад
Good job
@dimasandrianoh3811
@dimasandrianoh3811 8 месяцев назад
Thanks sir, but i have question. why u still create api route if only with server action can create user or login (logic in server action)?
@codingwithrobby
@codingwithrobby 8 месяцев назад
Yeah... I suppose that would work too 😬. I guess this just adds a little more flexibility if you wanted to open it up externally down the line.
@victor63666
@victor63666 7 месяцев назад
I believe that when utilizing server actions, you are essentially making a POST request to an endpoint representing the server action function. In this context, it seems like you are engaging in two fetch operations. I think you can invoke this function within both the signup route and the signup server action. @@codingwithrobby
@TomislavKimovski
@TomislavKimovski 6 месяцев назад
Not really needed, but it was good to see how to set up api endpoints if needed.
@TomislavKimovski
@TomislavKimovski 6 месяцев назад
Brilliant, loved it! Referencing the docs was a great idea, made everything look so simple.
@iancarr3923
@iancarr3923 6 месяцев назад
Excellent!
@victorchukwu6671
@victorchukwu6671 3 месяца назад
Thanks so much
@w3mw
@w3mw 5 месяцев назад
Great video thanks, but if you have a user and want to display the information or store it somehow in a useContext to be able to use the users information around the app, will I just put cookies().get("Authentication") into a authContext then?
@CarltonJosephLv
@CarltonJosephLv 8 месяцев назад
Thanks!
@BoomOzi
@BoomOzi 3 месяца назад
how to logout?
@韩佳骏
@韩佳骏 4 месяца назад
How to Log out?
@prashlovessamosa
@prashlovessamosa 8 месяцев назад
Thanks
@macccu
@macccu 5 месяцев назад
Why are you making server-side request in server action to your own api? This makes no sense. Please stop.
@codingwithrobby
@codingwithrobby 5 месяцев назад
😳
@ahmedmrsawy9215
@ahmedmrsawy9215 6 месяцев назад
Sorry but using server action to make a request to a route handler is so DUMP
@chulada03
@chulada03 8 месяцев назад
Thanks
Далее
Next.js with a separate server - good idea?
22:53
Просмотров 66 тыс.
Next.js Server Actions...  5 awesome things you can do
7:51
Serverless Auth with Lucia Auth V3
27:46
Просмотров 9 тыс.
Supabase and NextJS 14:  Auth and Server Actions
1:19:31