Skip to content

Commit

Permalink
Update Index.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcrair committed Apr 1, 2024
1 parent 7a48f95 commit 799d974
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions src/app/Index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,18 @@ import { loginWithSpotify } from "@/app/login/actions";
import Ipod from "@/components/svg-art/ipod";
import "@/app/globals.css";
import LeftPanel from "@/components/svg-art/left_panel";
import createClient from "@/utils/supabase/client";

export default function IndexContent() {
const [userData, setUser] = useState(null);
const supabase = createClient();

const [loggedIn, setLogIn] = useState(false);
const [cookies] = useCookies();

// check if user is already logged in
useEffect(() => {
(async () => {
// console.log("use effect running");
const {
data: { user },
} = await supabase.auth.getUser();
// console.log("user: ", user);
if (user && cookies && Object.keys(cookies).length > 0) {
// already logged in
// console.log("logged in");
setUser("user");
}
})().catch(() => {
// TODO display error message to user
});
if (cookies && Object.keys(cookies).length > 0) {
// already logged in
// console.log("logged in");
setLogIn(true);
}
}, []);

function handleSignOut() {
Expand Down Expand Up @@ -76,9 +64,7 @@ export default function IndexContent() {
type="button"
onClick={() => loginWithSpotify()}
>
{userData !== null
? "Continue to Account"
: "Log in with Spotify"}
{loggedIn ? "Continue to Account" : "Log in with Spotify"}
</button>
<button
className="border rounded-full bg-white px-5 py-3 text-3xl font-koulen \
Expand Down

0 comments on commit 799d974

Please sign in to comment.