From bfdd33cc4532ae670202f2d5a63fd42f778376b2 Mon Sep 17 00:00:00 2001 From: NancyAanchal Date: Wed, 14 Aug 2024 11:16:06 +0545 Subject: [PATCH] tried fixing forgot-pwd --- nepalingo-web/src/hooks/Auth.tsx | 6 +++-- nepalingo-web/src/pages/ResetPassword.tsx | 30 ++++++++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/nepalingo-web/src/hooks/Auth.tsx b/nepalingo-web/src/hooks/Auth.tsx index 88d309d..c7e0321 100644 --- a/nepalingo-web/src/hooks/Auth.tsx +++ b/nepalingo-web/src/hooks/Auth.tsx @@ -27,7 +27,8 @@ const AuthContext = createContext({ signIn: (data) => supabaseClient.auth.signInWithPassword(data), resetPasswordEmail: (email) => supabaseClient.auth.resetPasswordForEmail(email, { - redirectTo: "https://www.nepalingo.com/reset-password", + //redirectTo: "https://www.nepalingo.com/reset-password", + redirectTo: "http://localhost:5173/reset-password", }), }); @@ -71,7 +72,8 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => { signIn: (data) => supabaseClient.auth.signInWithPassword(data), resetPasswordEmail: (email) => supabaseClient.auth.resetPasswordForEmail(email, { - redirectTo: "https://www.nepalingo.com/reset-password", + //redirectTo: "https://www.nepalingo.com/reset-password", + redirectTo: "http://localhost:5173/reset-password", }), }; diff --git a/nepalingo-web/src/pages/ResetPassword.tsx b/nepalingo-web/src/pages/ResetPassword.tsx index b4b21fa..93278a1 100644 --- a/nepalingo-web/src/pages/ResetPassword.tsx +++ b/nepalingo-web/src/pages/ResetPassword.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { useNavigate } from "react-router-dom"; import CustomTextInput from "@/components/CustomTextInput"; import Button from "@/components/Button"; @@ -24,7 +24,7 @@ const ResetPassword: React.FC = () => { // Update the password using the Supabase client const { error: updateError } = await supabaseClient.auth.updateUser({ - password, + password: password, }); if (updateError) { @@ -32,13 +32,35 @@ const ResetPassword: React.FC = () => { } else { navigate("/login", { state: { - message: - "Password reset successful! Please log in with your new password.", + message: "Password reset successful!", }, }); } }; + useEffect(() => { + const handleSessionFromURL = async () => { + // Extract session-related parameters from the URL + const urlParams = new URLSearchParams(window.location.search); + const accessToken = urlParams.get("access_token"); + const refreshToken = urlParams.get("refresh_token"); + + if (accessToken && refreshToken) { + // Set the session in Supabase + const { error } = await supabaseClient.auth.setSession({ + access_token: accessToken, + refresh_token: refreshToken, + }); + + if (error) { + setError("Failed to restore session. Please try again."); + } + } + }; + + handleSessionFromURL(); + }, []); + return (