feat: format with prettier

This commit is contained in:
swve 2024-02-09 21:22:15 +01:00
parent 03fb09c3d6
commit a147ad6610
164 changed files with 11257 additions and 8154 deletions

View file

@ -1,71 +1,79 @@
"use client";
import React from "react";
import styled from "styled-components";
import Link from "next/link";
import { getNewAccessTokenUsingRefreshToken, getUserInfo } from "@services/auth/auth";
import { usePathname } from "next/navigation";
import { useRouter } from "next/router";
import { Settings } from "lucide-react";
import UserAvatar from "@components/Objects/UserAvatar";
'use client'
import React from 'react'
import styled from 'styled-components'
import Link from 'next/link'
import {
getNewAccessTokenUsingRefreshToken,
getUserInfo,
} from '@services/auth/auth'
import { usePathname } from 'next/navigation'
import { useRouter } from 'next/router'
import { Settings } from 'lucide-react'
import UserAvatar from '@components/Objects/UserAvatar'
export interface Auth {
access_token: string;
isAuthenticated: boolean;
userInfo: any;
isLoading: boolean;
access_token: string
isAuthenticated: boolean
userInfo: any
isLoading: boolean
}
function ProfileArea() {
const PRIVATE_ROUTES = ['/course/*/edit', '/settings*', '/trail']
const NON_AUTHENTICATED_ROUTES = ['/login', '/register']
const PRIVATE_ROUTES = ["/course/*/edit", "/settings*", "/trail"];
const NON_AUTHENTICATED_ROUTES = ["/login", "/register"];
const router = useRouter();
const pathname = usePathname();
const [auth, setAuth] = React.useState<Auth>({ access_token: "", isAuthenticated: false, userInfo: {}, isLoading: true });
const router = useRouter()
const pathname = usePathname()
const [auth, setAuth] = React.useState<Auth>({
access_token: '',
isAuthenticated: false,
userInfo: {},
isLoading: true,
})
async function checkRefreshToken() {
let data = await getNewAccessTokenUsingRefreshToken();
let data = await getNewAccessTokenUsingRefreshToken()
if (data) {
return data.access_token;
return data.access_token
}
}
React.useEffect(() => {
checkAuth();
}, [pathname]);
checkAuth()
}, [pathname])
async function checkAuth() {
try {
let access_token = await checkRefreshToken();
let userInfo = {};
let isLoading = false;
let access_token = await checkRefreshToken()
let userInfo = {}
let isLoading = false
if (access_token) {
userInfo = await getUserInfo(access_token);
setAuth({ access_token, isAuthenticated: true, userInfo, isLoading });
userInfo = await getUserInfo(access_token)
setAuth({ access_token, isAuthenticated: true, userInfo, isLoading })
// Redirect to home if user is trying to access a NON_AUTHENTICATED_ROUTES route
if (NON_AUTHENTICATED_ROUTES.some((route) => new RegExp(`^${route.replace("*", ".*")}$`).test(pathname))) {
router.push("/");
if (
NON_AUTHENTICATED_ROUTES.some((route) =>
new RegExp(`^${route.replace('*', '.*')}$`).test(pathname)
)
) {
router.push('/')
}
} else {
setAuth({ access_token, isAuthenticated: false, userInfo, isLoading });
setAuth({ access_token, isAuthenticated: false, userInfo, isLoading })
// Redirect to login if user is trying to access a private route
if (PRIVATE_ROUTES.some((route) => new RegExp(`^${route.replace("*", ".*")}$`).test(pathname))) {
router.push("/login");
if (
PRIVATE_ROUTES.some((route) =>
new RegExp(`^${route.replace('*', '.*')}$`).test(pathname)
)
) {
router.push('/login')
}
}
} catch (error) {
}
} catch (error) {}
}
return (
<ProfileAreaStyled>
@ -73,14 +81,10 @@ function ProfileArea() {
<UnidentifiedArea>
<ul>
<li>
<Link href="/login">
Login
</Link>
<Link href="/login">Login</Link>
</li>
<li>
<Link href="/signup">
Sign up
</Link>
<Link href="/signup">Sign up</Link>
</li>
</ul>
</UnidentifiedArea>
@ -89,9 +93,11 @@ function ProfileArea() {
<AccountArea>
<div>{auth.userInfo.user_object.username}</div>
<div>
<UserAvatar width={40} />
<UserAvatar width={40} />
</div>
<Link href={"/dash"}><Settings /></Link>
<Link href={'/dash'}>
<Settings />
</Link>
</AccountArea>
)}
</ProfileAreaStyled>
@ -103,8 +109,6 @@ const AccountArea = styled.div`
display: flex;
place-items: center;
div {
margin-right: 10px;
}
@ -112,13 +116,13 @@ const AccountArea = styled.div`
width: 29px;
border-radius: 19px;
}
`;
`
const ProfileAreaStyled = styled.div`
display: flex;
place-items: stretch;
place-items: center;
`;
`
const UnidentifiedArea = styled.div`
display: flex;
@ -138,7 +142,6 @@ const UnidentifiedArea = styled.div`
color: #171717;
}
}
`;
`
export default ProfileArea
export default ProfileArea