Skip to content
Snippets Groups Projects
Commit c7feda8c authored by Matt Kirby's avatar Matt Kirby
Browse files

uses useUser (lol) hook

parent 52994138
No related branches found
No related tags found
1 merge request!18Fe search and friends (sorry in advance)
......@@ -2,6 +2,7 @@ import NavBar from "@/components/navigation/NavBar";
import AnswerCard from "@/components/post/AnswerCard";
import Post from "@/components/post/Post";
import Question from "@/components/question/Question";
import { useUser } from "@/hooks/useUser";
import { User } from "@/types/user";
import Router from "next/router";
import { useEffect, useState } from "react";
......@@ -16,33 +17,7 @@ const userx = {
}
const Feed = () => {
const [user, setUser] = useState<undefined | User>(undefined)
const fetchUser = async () => {
const endpoint = `${process.env.NEXT_PUBLIC_USER_SERVICE_URL}api/user/${sessionStorage.getItem('username')}`
const response = await fetch(endpoint)
return await response.json()
}
useEffect(() => {
if(sessionStorage.length < 2){
Router.push("/")
}
})
useEffect(() => {
if(!user){
fetchUser().then(res => {
const {_id, username, email, profile, firstName, lastName } = res
setUser({id: _id, email, username, profile, firstName, lastName})
})
}
})
const user = useUser()
return(
<>
<div className="w-full">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment