Skip to content

Commit

Permalink
feat: base user auth added
Browse files Browse the repository at this point in the history
  • Loading branch information
AidanTilgner committed Jul 1, 2023
1 parent 41b396a commit 9f34b76
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions client/Contexts/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export const UserProvider = ({
onSuccess: (res) => {
console.log("User loaded", res);
},
onFinally: () => {
console.log("User load finished");
},
});

const value: UserContextValue = useMemo(
Expand Down
7 changes: 7 additions & 0 deletions client/pages/Home/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.home {
p {
a {
color: var(--text-color);
}
}
}
5 changes: 3 additions & 2 deletions client/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import React from "react";
import { useUser } from "../../Contexts/User";
import { Link } from "react-router-dom";
import { logout } from "../../utils/auth";
import styles from "./index.module.scss";

function index() {
const { isLoggedIn } = useUser();

return (
<div>
<div className={styles.home}>
{isLoggedIn ? (
<p>Looks like you're logged in!</p>
) : (
<p>
Looks like you're not logged in. <Link to="/login">Login</Link> or{" "}
<Link to="/signup">Signup</Link>
<Link to="/signup">Signup</Link>.
</p>
)}
{isLoggedIn && (
Expand Down
5 changes: 4 additions & 1 deletion client/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import jwtDecode from "jwt-decode";
import { api } from "./axios";

export const getLoginUrl = (currentURL: string, reason: string) => {
const query = new URLSearchParams({ redirectUrl: currentURL, reason });
const query = new URLSearchParams({
redirectUrl: currentURL,
reason: reason || "none",
});
return `/login?${query.toString()}`;
};

Expand Down

0 comments on commit 9f34b76

Please sign in to comment.