redirecting from the router to team dashboard if user is in a team

This commit is contained in:
Arjun Patel
2022-01-14 13:22:30 -08:00
parent 10b52fbe0d
commit a0c36ec924
2 changed files with 41 additions and 1 deletions
+12 -1
View File
@@ -13,14 +13,19 @@ import {
FaBullhorn
} from "react-icons/fa";
import BackgroundLayout from "../../components/Layouts/BackgroundLayout"
import TeamService from "../../services/teamService"
/**
* figure out where to take the user based on everything
*/
const userService: UserService = new UserService()
const teamService: TeamService = new TeamService()
function RouteHandler() {
const { currUser } = useAuth()
const router = useRouter()
const userService: UserService = new UserService()
const [loading, setLoading] = useState<Boolean>(true)
const [user, setUser] = useState<User | null>(null)
@@ -44,6 +49,12 @@ function RouteHandler() {
setUser(returnedUser)
// check if user is in a team go to the team dashboard
const returnedTeamMembers = await teamService.getTeamMembersByUserId(currUser.uid)
if (returnedTeamMembers.length > 0) {
console.log('in a team! going to the team dashboard of the first one!')
router.push('/teams/' + returnedTeamMembers[0].teamId)
return
}
} catch(error) {
console.log(error)