Skip to content

Commit

Permalink
Merge pull request #216 from nepalcodes/forgot-pwd-fix
Browse files Browse the repository at this point in the history
tried fixing forgot-pwd
  • Loading branch information
NancyAanchal authored Aug 15, 2024
2 parents ae7a21f + 7a867f0 commit 0022665
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
6 changes: 4 additions & 2 deletions nepalingo-web/src/hooks/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const AuthContext = createContext<AuthContextProps>({
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",
}),
});

Expand Down Expand Up @@ -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",
}),
};

Expand Down
30 changes: 26 additions & 4 deletions nepalingo-web/src/pages/ResetPassword.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -24,21 +24,43 @@ const ResetPassword: React.FC = () => {

// Update the password using the Supabase client
const { error: updateError } = await supabaseClient.auth.updateUser({
password,
password: password,
});

if (updateError) {
setError(updateError.message);
} 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 (
<div className="flex items-center justify-center min-h-screen bg-black">
<div className="bg-black p-8 rounded shadow-md w-full max-w-md">
Expand Down

0 comments on commit 0022665

Please sign in to comment.