mirror of
https://github.com/sigmasternchen/threadule
synced 2025-03-15 08:09:01 +00:00
added auth provider to frontend
This commit is contained in:
parent
9cb721ac7d
commit
5ba50cb2f6
2 changed files with 42 additions and 3 deletions
|
@ -1,11 +1,14 @@
|
|||
import React from 'react';
|
||||
import './App.css';
|
||||
import {AuthProvider} from "./auth/AuthProvider";
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<h1>Hi</h1>
|
||||
</div>
|
||||
<AuthProvider>
|
||||
<div className="App">
|
||||
<h1>Hi</h1>
|
||||
</div>
|
||||
</AuthProvider>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
36
frontend/src/auth/AuthProvider.tsx
Normal file
36
frontend/src/auth/AuthProvider.tsx
Normal file
|
@ -0,0 +1,36 @@
|
|||
import React, {FunctionComponent, useContext, useState} from "react";
|
||||
|
||||
type AuthState = {
|
||||
loggedIn: boolean
|
||||
|
||||
login: (username: string, password: string) => Promise<string>
|
||||
}
|
||||
|
||||
const emptyAuthState = {
|
||||
loggedIn: false,
|
||||
|
||||
login: async () => "not implemented"
|
||||
}
|
||||
|
||||
const AuthContext = React.createContext<AuthState>(emptyAuthState)
|
||||
|
||||
export const useAuth = () => {
|
||||
return useContext(AuthContext)
|
||||
}
|
||||
|
||||
type AuthProviderProps = {
|
||||
}
|
||||
|
||||
export const AuthProvider: FunctionComponent<AuthProviderProps> = ({children}) => {
|
||||
const defaultAuthState = {
|
||||
...emptyAuthState
|
||||
}
|
||||
|
||||
const [authState, setAuthState] = useState<AuthState>(defaultAuthState)
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={authState}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
)
|
||||
}
|
Loading…
Reference in a new issue