Skip to content

Commit

Permalink
feat: add new auth context provider to handle authentication state ap…
Browse files Browse the repository at this point in the history
…plication wide
  • Loading branch information
corp-0 committed Mar 8, 2024
1 parent 0d7d26e commit dec6c17
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Metadata} from "next";
import DefaultNavbar from "./common/defaultNavbar";
import { Analytics } from '@vercel/analytics/react';
import type { Viewport } from 'next'
import {Providers} from "./providers";

export const metadata: Metadata = {
title: 'Unitystation - The Space Station 13 Remake Made in Unity',
Expand Down Expand Up @@ -49,8 +50,10 @@ export default function RootLayout({children,}: { children: React.ReactNode; })
<html>
<body className="dark">
<Clown/>
<DefaultNavbar/>
{children}
<Providers>
<DefaultNavbar/>
{children}
</Providers>
<Analytics />
</body>
</html>
Expand Down
13 changes: 13 additions & 0 deletions app/providers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use client'

import LayoutChildren from "../types/layoutChildren";
import {AuthorizerContext} from "../context/authorizerContext";

export const Providers = (props: LayoutChildren) => {

return (
<AuthorizerContext.Provider value={{isLoggedIn: false}}>
{props.children}
</AuthorizerContext.Provider>
)
}
7 changes: 7 additions & 0 deletions context/authorizerContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {createContext} from "react";
import {AuthContext} from "../types/authTypes";

export const AuthorizerContext = createContext<AuthContext>({
isLoggedIn: false
}
)
22 changes: 22 additions & 0 deletions types/authTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export interface AccountPublicData {
unique_identifier: string;
username: string;
legacy_id?: string;
is_verified: boolean;
}

export interface LoginResponse {
account: AccountPublicData;
token: string;
}

export interface LoginWithCredentialsRequest {
email: string;
password: string;
}

export interface AuthContext {
isLoggedIn: boolean;
account?: AccountPublicData;
encryptedToken?: string;
}

0 comments on commit dec6c17

Please sign in to comment.