-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for user login
- Loading branch information
Showing
21 changed files
with
938 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { RdsApi } from "./rds.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { rdsClient } from "@/utils/client" | ||
import { RdsUserSelfResDto } from "./rds.dto" | ||
|
||
export class RdsApi { | ||
public static async getCurrentUserData(): Promise<RdsUserSelfResDto> { | ||
const { data } = await rdsClient.get("/users/self") | ||
return data | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export type RdsUserSelfResDto = { | ||
id: string | ||
incompleteUserDetails: boolean | ||
discordJoinedAt: string | ||
discordId: string | ||
roles: { | ||
archived: boolean | ||
in_discord: boolean | ||
member: boolean | ||
} | ||
linkedin_id: boolean | ||
picture?: { | ||
url: string | ||
publicId: string | ||
} | ||
yoe: number | ||
github_created_at: number | ||
github_display_name: string | ||
github_id: string | ||
twitter_id: string | ||
username: string | ||
github_user_id: string | ||
first_name: string | ||
profileURL: string | ||
website: string | ||
last_name: string | ||
company: string | ||
designation: string | ||
instagram_id: string | ||
profileStatus: string // TODO: Make this a enum | ||
updated_at: number | ||
created_at: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { config } from "@/config" | ||
import Link from "next/link" | ||
import { SignInWithRds } from "./signin-with-rds" | ||
|
||
type NavLinksList = { | ||
className?: string | ||
children: React.ReactNode | ||
} | ||
|
||
const NavLinksList = ({ className, children }: NavLinksList) => { | ||
return <ul className={className}>{children}</ul> | ||
} | ||
|
||
type NavLinkProps = { | ||
href: string | ||
children: React.ReactNode | ||
} | ||
|
||
const NavLink = ({ href, children }: NavLinkProps) => { | ||
return ( | ||
<li className="rounded-full px-4 py-1 transition-all ease-in-out hover:bg-gray-100"> | ||
<Link href={href}>{children}</Link> | ||
</li> | ||
) | ||
} | ||
|
||
export const Navbar = () => { | ||
return ( | ||
<nav className="fixed left-0 top-0 w-full bg-white"> | ||
<div className="mx-auto flex h-14 w-full max-w-screen-2xl items-center gap-6 px-6"> | ||
<h1 className="text-xl font-bold">Rds</h1> | ||
|
||
<NavLinksList className="flex items-center"> | ||
<NavLink href={config.welcomeSiteUrl}>Welcome</NavLink> | ||
<NavLink href={config.membersSiteUrl}>Members</NavLink> | ||
<NavLink href={config.membersSiteUrl}>Status</NavLink> | ||
</NavLinksList> | ||
|
||
<div className="ml-auto"> | ||
<SignInWithRds /> | ||
</div> | ||
</div> | ||
</nav> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { config } from "@/config" | ||
import { ROUTES } from "@/routes" | ||
import { useGlobalStore } from "@/store/global-store" | ||
import Image from "next/image" | ||
import { useRouter } from "next/navigation" | ||
|
||
export const SignInWithRds = () => { | ||
const { push } = useRouter() | ||
const { user } = useGlobalStore((store) => ({ user: store.user })) | ||
|
||
const handleSignIn = async () => { | ||
const redirectUrl = `${config.skillTreeUrl}${ROUTES.requests}` | ||
const url = `${config.rdsBackendBaseUrl}/auth/github/login?redirectURL=${redirectUrl}?v2=true` | ||
|
||
push(url) | ||
} | ||
|
||
// TODO : make a separate component for this | ||
if (user) { | ||
return ( | ||
<div className="flex items-center gap-2"> | ||
<Image | ||
src={user.profilePicture} | ||
alt={user.name} | ||
width={64} | ||
height={64} | ||
className="h-7 w-7 overflow-hidden rounded-full" | ||
/> | ||
|
||
<span className="inline-block">{user.name}</span> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<button | ||
onClick={handleSignIn} | ||
className="h-9 rounded-lg bg-gray-200 px-4 font-medium text-gray-700 transition hover:bg-gray-300" | ||
> | ||
SignIn within rds | ||
</button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { RdsApi } from "@/api/rds" | ||
import { ROUTES } from "@/routes" | ||
import { TGlobalStoreUser, useGlobalStore } from "@/store/global-store" | ||
import { useQuery } from "@tanstack/react-query" | ||
import { usePathname } from "next/navigation" | ||
import { useEffect } from "react" | ||
|
||
type Props = { | ||
children: React.ReactNode | ||
} | ||
|
||
const UNPROTECTED_PATHS = [ROUTES.root, ROUTES.signIn] | ||
|
||
export const UserGuard = ({ children }: Props) => { | ||
const pathname = usePathname() | ||
const isUnprotectedPath = UNPROTECTED_PATHS.includes(pathname) | ||
const { setGlobalStore } = useGlobalStore((store) => ({ setGlobalStore: store.setGlobalStore })) | ||
|
||
const { data, isLoading, isError } = useQuery({ | ||
enabled: !isUnprotectedPath, | ||
queryKey: ["RdsApi.getCurrentUserData"], | ||
queryFn: RdsApi.getCurrentUserData, | ||
}) | ||
|
||
useEffect(() => { | ||
if (!data) { | ||
return | ||
} | ||
|
||
const firstName = data?.first_name ?? "" | ||
const lastName = data?.last_name ?? "" | ||
|
||
const user: TGlobalStoreUser = { | ||
id: data.id, | ||
name: firstName + " " + lastName, | ||
profilePicture: data?.picture?.url ?? "", | ||
} | ||
|
||
setGlobalStore({ user }) | ||
}, [data]) | ||
|
||
if (isLoading) { | ||
return <div>Loading...</div> | ||
} | ||
|
||
if (isError) { | ||
return <div>Error...</div> | ||
} | ||
|
||
return <>{children}</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Requests } from "./requests" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Navbar } from "@/components/navbar" | ||
|
||
export const Requests = () => { | ||
return ( | ||
<div> | ||
<Navbar /> | ||
|
||
<main className="mx-auto mt-14 max-w-screen-2xl p-6"> | ||
<h1 className="pb-6">Requests</h1> | ||
</main> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,23 @@ | ||
import type { ReactElement, ReactNode } from "react"; | ||
import type { NextPage } from "next"; | ||
import type { AppProps } from "next/app"; | ||
|
||
import { validateEnv } from "@/config"; | ||
import "@/styles/global.css"; | ||
import { Providers } from "@/utils/providers"; | ||
import type { AppProps } from "next/app" | ||
|
||
import { validateEnv } from "@/config" | ||
import "@/styles/global.css" | ||
import { Providers } from "@/utils/providers" | ||
import { UserGuard } from "@/components/user-guard" | ||
|
||
/** | ||
* Validate if all the required environment variables are set | ||
* this will allow us to fail fast if any of the required environment variables are not set | ||
* --- | ||
*/ | ||
validateEnv(); | ||
|
||
|
||
export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & { | ||
getLayout?: (page: ReactElement) => ReactNode | ||
} | ||
|
||
type AppPropsWithLayout = AppProps & { | ||
Component: NextPageWithLayout | ||
} | ||
|
||
export default function App({ Component, pageProps }: AppPropsWithLayout) { | ||
// For more info on this pattern visit: https://nextjs.org/docs/pages/building-your-application/routing/pages-and-layouts#with-typescript | ||
const getLayout = Component.getLayout ?? ((page) => page); | ||
* --- | ||
*/ | ||
validateEnv() | ||
|
||
export default function MyApp({ Component, pageProps }: AppProps) { | ||
return ( | ||
<Providers> | ||
{/* @ts-ignore */} | ||
{getLayout(<Component {...pageProps} />)} | ||
<UserGuard> | ||
<Component {...pageProps} /> | ||
</UserGuard> | ||
</Providers> | ||
); | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
export default function Home() { | ||
import { ROUTES } from "@/routes" | ||
import Link from "next/link" | ||
|
||
const Homepage = () => { | ||
return ( | ||
<div> | ||
<div> | ||
Homepage | ||
</div> | ||
<div className="flex h-screen w-screen flex-col items-center justify-center"> | ||
<h1 className="pb-1 text-4xl font-bold">Welcome to Skilltree</h1> | ||
<p className="text-sm text-gray-500"> | ||
Visit{" "} | ||
<Link className="text-blue-500 hover:text-blue-600 hover:underline" href={ROUTES.requests}> | ||
/requests | ||
</Link>{" "} | ||
to view all pending skill requests | ||
</p> | ||
</div> | ||
); | ||
) | ||
} | ||
|
||
export default Homepage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Requests } from "@/modules/requests" | ||
|
||
export default Requests |
Oops, something went wrong.