Skip to content

Commit

Permalink
route to Dashboard after clicking magic link
Browse files Browse the repository at this point in the history
  • Loading branch information
acao22 committed Jul 19, 2024
1 parent ba9c8b4 commit 2cdc950
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
16 changes: 8 additions & 8 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ const App = () => {
const response = await Backend.post(`/users/verify`);
return response.data.ok
? dispatch(
setUserData({
loggedIn: true,
email: response.data.email,
token: token,
surveySession: response.data.sessionId,
})
)
setUserData({
loggedIn: true,
email: response.data.email,
token: token,
surveySession: response.data.sessionId,
})
)
: dispatch(clearUserData());
} catch (error) {}
} catch (error) { }
};
verify_token();
}, [token]);
Expand Down
1 change: 1 addition & 0 deletions client/src/components/Enter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Enter: React.FC<EnterProps> = ({ signIn }) => {
} else {
// Handle the case where either params.email or params.link is undefined
console.error("Email or link is missing");
navigate("/dashboard");
}
}, [params.email, params.link, navigate, signIn]);

Expand Down
16 changes: 16 additions & 0 deletions client/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ const Dashboard: React.FC = () => {
}
};

const signOut = async () => {
try {
Backend.defaults.headers.common["Authorization"] = token;
const response = await Backend.post("/users/deleteaccount", {
email: "",
});
return response.data.ok;
} catch (error) {
console.log(error);
}
};

useEffect(() => {
if (!loggedIn) {
navigate("/signin");
Expand Down Expand Up @@ -398,6 +410,10 @@ const Dashboard: React.FC = () => {
{/* Delete account */}
{t("dashboard.delete-account")}
</button>
<button onClick={signOut}>
{/* Delete account */}
{t("dashboard.signout")}
</button>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions client/src/pages/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const SignIn: React.FC = () => {
} catch (error) {
console.log(error);
}

};

const enterEmail = (e: ChangeEvent<HTMLInputElement>) => {
Expand Down
15 changes: 13 additions & 2 deletions server/controllers/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ const ses = new aws.SES({
});

// create Nodemailer SES transporter
let transporter = nodemailer.createTransport({
SES: { ses, aws },
// let transporter = nodemailer.createTransport({
// SES: { ses, aws },
// });

const transporter = nodemailer.createTransport({
service: "Gmail",
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
user: process.env.NODEMAILER_EMAIL,
pass: process.env.NODEMAILER_PASSWORD,
},
});

const URL =
Expand Down

0 comments on commit 2cdc950

Please sign in to comment.