NextJS Project Tutorial - Protecting User Routes - 14

  Рет қаралды 11,292

Rizwan Khan

Rizwan Khan

Күн бұрын

Пікірлер: 18
@somyaranjankhatua7746
@somyaranjankhatua7746 3 жыл бұрын
How to integrate shipping api in node js
@santrawebtech35
@santrawebtech35 3 жыл бұрын
sir how many class are left sir
@suyashsrivastava3671
@suyashsrivastava3671 2 жыл бұрын
How do we solve the 0.5 sec delay in rerouting ? It can lead to some leak in information
@farrukhahmad1430
@farrukhahmad1430 2 жыл бұрын
use "next-shield" library
@45Faraz
@45Faraz 2 жыл бұрын
@@farrukhahmad1430 Brother your comment saved me. Thank you!🙂
@thehkmalhotra9714
@thehkmalhotra9714 Жыл бұрын
@@farrukhahmad1430 Hey thanks for your comment. Actually I am looking for a tutorial based on next-shield. Like how exactly I can fix that few seconds of delay between these 2 pages. Thanks in advance.
@farrukhahmad1430
@farrukhahmad1430 Жыл бұрын
@@thehkmalhotra9714 next-shield documentation is pretty easy and understandable. Another solution is using next “middleware”, it runs before every request and you can protect routes and reroute users based on your conditions. Hint: you can access cookies
@bilalch898
@bilalch898 2 жыл бұрын
clearly not a better user experience. user will always see that jerk transition on the header that occurs when first page load because initially the user is not authenticated, and after a sec the user is detected and is set to authenticated, fix that jerk, otherwise this solution is certainly worst for a production level app.
@timothysteele4828
@timothysteele4828 3 жыл бұрын
Hi Riwan Please my problem is now that if am updating my profile, like role of user my session does not update but i can update the data store in local storage my question is how to i update the session without signing out and signing again thank you
@RizwanKhanDeveloper
@RizwanKhanDeveloper 3 жыл бұрын
You don’t have to signout and Signin by yourself just update the role of user and on success of it call signin method from nextAuth and in authorise method call getSession and if session is valid then return user with updated role
@timothysteele4828
@timothysteele4828 3 жыл бұрын
@@RizwanKhanDeveloper ok let me try that thanks
@timothysteele4828
@timothysteele4828 3 жыл бұрын
@@RizwanKhanDeveloper hi Rizwan the below code allow user to update his role to an author and works find, it allow user to his role also in local storage const handleBecomeAuthor = async (e) => { let session = await getSession(); try { setSaving(true); let { data } = await axios.put(`/api/author`); dispatch({ type: 'UPDATE_SUCCESS', payload: data, }); session = data; window.localStorage.setItem('user', JSON.stringify(data)); toast.success('Success'); setSaving(false); } catch (err) { console.log(err); setSaving(false); } }; This next line of code is the modification that will allow the user to update the session but it is not working as u said may be am doing it wrong and you can take a look at it const handleBecomeAuthor = async (e) => { let session = await getSession(); try { setSaving(true); let { data } = await axios.put(`/api/author`); dispatch({ type: 'UPDATE_SUCCESS', payload: data, }); session = data; window.localStorage.setItem('user', JSON.stringify(data)); ****************************************************************************** const result = await signIn('credentials', { redirect: false, email, password, }); if (!result.error) { dispatch({ type: 'LOGIN', payload: session, }); window.localStorage.setItem('user', JSON.stringify(session)); } else { toast.error(result.error); } ****************************************************************************** toast.success('Success'); setSaving(false); } catch (err) { console.log(err); setSaving(false); } }; where the stars begins and end is what i added to the above code and is not working please help
@RizwanKhanDeveloper
@RizwanKhanDeveloper 3 жыл бұрын
@@timothysteele4828 after role update you call signin(“credentials”) no need to give email and password as you already logged in. Now switch to authorize(credential) and here use getSession to get user session and if session exists then return user directly
@timothysteele4828
@timothysteele4828 3 жыл бұрын
@@RizwanKhanDeveloper Hi thanks for your help so far but is not work when i call signIn("credentials") with this it ask for the email, and password to be provided if i also provide email and password still those not work
@digvijayrana340
@digvijayrana340 2 жыл бұрын
can you please provide the full code for this
@sikanderahmad9371
@sikanderahmad9371 2 жыл бұрын
source code please
Next-Auth on App Router - Solid Auth, Super Fast
17:20
Jack Herrington
Рет қаралды 123 М.
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН
Protect Your API - Next Auth Middleware
8:05
Full Stack Niraj
Рет қаралды 35 М.
How to Protect Routes in Next.js 14 in 4 Ways - Private Routes - Authorization
27:47
Next.js 13 - The Basics
9:00
Beyond Fireship
Рет қаралды 714 М.
NextJS 13 API Routes: Better Than Expected!
15:05
Josh tried coding
Рет қаралды 113 М.
They made React great again?
4:11
Fireship
Рет қаралды 1,1 МЛН
NextJS Project Tutorial - User Authentication using JWT - 12
31:11
why rust libraries may never exist.
7:26
Low Level
Рет қаралды 286 М.
Code a Reddit Clone with React, Next.js, Firebase v9, Chakra UI - Full Course
11:43:32
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН