Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(frontend): go directly to dashboard if logged in #1355

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions frontend/dashboard/app/auth/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'use client';

import Link from "next/link";
import { useRouter } from "next/navigation";
import { useState, useEffect } from "react";
import Messages from "./messages"
import GoogleSignIn from "./google-sign-in"
import GitHubSignIn from "./github-sign-in"
import { auth, logout, getSession, decodeJWT } from "@/app/utils/auth/auth"
import { getSession, decodeJWT } from "@/app/utils/auth/auth"
import Script from "next/script"

export default function Login({ searchParams }: { searchParams: { [key: string]: string | string[] | undefined } }) {
Expand All @@ -18,11 +17,6 @@ export default function Login({ searchParams }: { searchParams: { [key: string]:
const router = useRouter()
const initial = !Boolean(error || message)

const logoutUser = async () => {
setHome("")
await logout(auth, router)
}

useEffect(() => {
setLoading(false)
const { session } = getSession()
Expand All @@ -33,14 +27,14 @@ export default function Login({ searchParams }: { searchParams: { [key: string]:
const { payload } = decodeJWT(session.access_token)
const url = `/${payload["team"]}/overview`
setHome(url)
router.replace(url)
}, [])

return (
<div className="min-h-screen flex flex-col items-center justify-center px-4 sm:px-6 lg:px-8">
{/* a fixed max-width is best as the google sign-in button has a width constraint */}
<div className="w-full space-y-6" style={{ width: "400px" }}>
{home && <Link href={home} className="block text-center hover:bg-yellow-200 active:bg-yellow-300 focus-visible:bg-yellow-200 border border-black rounded-md font-display text-black transition-colors duration-100 py-2 px-4 w-full">Go to dashboard</Link>}
{home && <button className="block text-center hover:bg-yellow-200 active:bg-yellow-300 focus-visible:bg-yellow-200 border border-black rounded-md font-display text-black transition-colors duration-100 py-2 px-4 w-full" onClick={() => logoutUser()}>Logout</button>}
{home && <p className="font-sans text-center">Logging in...</p>}
{!loggedIn && initial && (
<>
<Script src="https://accounts.google.com/gsi/client" />
Expand Down