How do we solve the 0.5 sec delay in rerouting ? It can lead to some leak in information
@farrukhahmad14302 жыл бұрын
use "next-shield" library
@45Faraz2 жыл бұрын
@@farrukhahmad1430 Brother your comment saved me. Thank you!🙂
@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 Жыл бұрын
@@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
@bilalch8982 жыл бұрын
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.
@timothysteele48283 жыл бұрын
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
@RizwanKhanDeveloper3 жыл бұрын
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
@timothysteele48283 жыл бұрын
@@RizwanKhanDeveloper ok let me try that thanks
@timothysteele48283 жыл бұрын
@@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
@RizwanKhanDeveloper3 жыл бұрын
@@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
@timothysteele48283 жыл бұрын
@@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