Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tried fixing forgot-pwd #216

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading