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

  Рет қаралды 1,251

Ugur Codes

Ugur Codes

3 ай бұрын

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...

Пікірлер: 22
@codernerd7076
@codernerd7076 2 ай бұрын
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 2 ай бұрын
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 2 ай бұрын
@@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 Ай бұрын
@@ugurcodes I'm sorry, but what exactly should we do to solve this problem?
@en_kratia
@en_kratia Ай бұрын
@@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 ай бұрын
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 3 ай бұрын
amazing video
@ugurcodes
@ugurcodes 3 ай бұрын
Thanks!!
@cicikuscicikus2381
@cicikuscicikus2381 3 ай бұрын
Wow amazing video
@lovrozagar3729
@lovrozagar3729 2 ай бұрын
Please do a Lucia Facebook OAuth guide 🙏
@xico6814
@xico6814 2 ай бұрын
now some role based protection page :D?
@ugurcodes
@ugurcodes 2 ай бұрын
Here you go! kzbin.info/www/bejne/bnKZqId9et5_jqc
@a7kerkh
@a7kerkh 2 ай бұрын
there is security issue, someone can still cookies and send scrf request to server then get user data
@codelivewithme
@codelivewithme 13 күн бұрын
so we must should do auth in middleware
@mrfirstname578
@mrfirstname578 3 ай бұрын
can i use lucia auth with other backend like php, phyton
@ugurcodes
@ugurcodes 3 ай бұрын
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 3 ай бұрын
@@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 17 күн бұрын
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.
@jean-claude-van-debug
@jean-claude-van-debug 10 күн бұрын
Why do people like to say what's good and what's bad without any context or explanation. Can you explain why "Auth logic on the client is generally a horrible idea", and how the hell did we make all those SPA's before nextjs and similar frameworks came out if that is the case?
Oh, Auth Doesn't Have to Suck?
7:16
Josh tried coding
Рет қаралды 52 М.
Они убрались очень быстро!
00:40
Аришнев
Рет қаралды 2,8 МЛН
They RUINED Everything! 😢
00:31
Carter Sharer
Рет қаралды 23 МЛН
Китайка и Пчелка 4 серия😂😆
00:19
KITAYKA
Рет қаралды 3,6 МЛН
Kinde: The Best Auth Solution Next.js 14
14:00
Sam Meech-Ward
Рет қаралды 8 М.
That's NOT How Async And Await Works in .NET!
12:25
Codewrinkles
Рет қаралды 14 М.
How I Authenticate my Sveltekit Apps
21:31
Ben Davis - Tech
Рет қаралды 7 М.
The Story of Next.js
12:13
uidotdev
Рет қаралды 541 М.
Generics: The most intimidating TypeScript feature
18:19
Matt Pocock
Рет қаралды 162 М.