Skip to content

Commit dec6c17

Browse files
committed
feat: add new auth context provider to handle authentication state application wide
1 parent 0d7d26e commit dec6c17

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

Diff for: app/layout.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Metadata} from "next";
55
import DefaultNavbar from "./common/defaultNavbar";
66
import { Analytics } from '@vercel/analytics/react';
77
import type { Viewport } from 'next'
8+
import {Providers} from "./providers";
89

910
export const metadata: Metadata = {
1011
title: 'Unitystation - The Space Station 13 Remake Made in Unity',
@@ -49,8 +50,10 @@ export default function RootLayout({children,}: { children: React.ReactNode; })
4950
<html>
5051
<body className="dark">
5152
<Clown/>
52-
<DefaultNavbar/>
53-
{children}
53+
<Providers>
54+
<DefaultNavbar/>
55+
{children}
56+
</Providers>
5457
<Analytics />
5558
</body>
5659
</html>

Diff for: app/providers.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use client'
2+
3+
import LayoutChildren from "../types/layoutChildren";
4+
import {AuthorizerContext} from "../context/authorizerContext";
5+
6+
export const Providers = (props: LayoutChildren) => {
7+
8+
return (
9+
<AuthorizerContext.Provider value={{isLoggedIn: false}}>
10+
{props.children}
11+
</AuthorizerContext.Provider>
12+
)
13+
}

Diff for: context/authorizerContext.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {createContext} from "react";
2+
import {AuthContext} from "../types/authTypes";
3+
4+
export const AuthorizerContext = createContext<AuthContext>({
5+
isLoggedIn: false
6+
}
7+
)

Diff for: types/authTypes.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export interface AccountPublicData {
2+
unique_identifier: string;
3+
username: string;
4+
legacy_id?: string;
5+
is_verified: boolean;
6+
}
7+
8+
export interface LoginResponse {
9+
account: AccountPublicData;
10+
token: string;
11+
}
12+
13+
export interface LoginWithCredentialsRequest {
14+
email: string;
15+
password: string;
16+
}
17+
18+
export interface AuthContext {
19+
isLoggedIn: boolean;
20+
account?: AccountPublicData;
21+
encryptedToken?: string;
22+
}

0 commit comments

Comments
 (0)