diff --git a/frontend/src/api/endpoints/AuthenticationEndpoint.ts b/frontend/src/api/endpoints/AuthenticationEndpoint.ts index 0254750..fb23f45 100644 --- a/frontend/src/api/endpoints/AuthenticationEndpoint.ts +++ b/frontend/src/api/endpoints/AuthenticationEndpoint.ts @@ -1,7 +1,6 @@ import Endpoint from "./Endpoint"; import {Client} from "../client"; import {LoginParams, LoginResponse} from "../entities/login"; -import User from "../entities/User"; const API_PREFIX = "/api/authentication/" @@ -13,10 +12,6 @@ class AuthenticationEndpoint extends Endpoint { public async login(params: LoginParams): Promise { return this.post(API_PREFIX, params) } - - public async getUser(): Promise { - return this.get(API_PREFIX) - } } export default AuthenticationEndpoint \ No newline at end of file diff --git a/frontend/src/api/endpoints/SelfEndpoint.ts b/frontend/src/api/endpoints/SelfEndpoint.ts new file mode 100644 index 0000000..5d0ae2e --- /dev/null +++ b/frontend/src/api/endpoints/SelfEndpoint.ts @@ -0,0 +1,17 @@ +import Endpoint from "./Endpoint"; +import {Client} from "../client"; +import User from "../entities/User"; + +const API_PREFIX = "/api/self/" + +class AuthenticationEndpoint extends Endpoint { + constructor(client: Client) { + super(client); + } + + public async getUser(): Promise { + return this.get(API_PREFIX) + } +} + +export default AuthenticationEndpoint \ No newline at end of file diff --git a/frontend/src/auth/AuthProvider.tsx b/frontend/src/auth/AuthProvider.tsx index 305e086..c9670d8 100644 --- a/frontend/src/auth/AuthProvider.tsx +++ b/frontend/src/auth/AuthProvider.tsx @@ -3,6 +3,7 @@ import AuthenticationEndpoint from "../api/endpoints/AuthenticationEndpoint"; import {Client, getClient} from "../api/client"; import User from "../api/entities/User"; import {Backdrop, CircularProgress} from "@material-ui/core"; +import SelfEndpoint from "../api/endpoints/SelfEndpoint"; type AuthState = { loggedIn: boolean @@ -55,8 +56,8 @@ const AuthProvider: FunctionComponent = ({children}) => { const client = getClient(response.token) // local new authenticationEndpoint - authenticationEndpoint = new AuthenticationEndpoint(client) - const user = await authenticationEndpoint.getUser() + const selfEndpoint = new SelfEndpoint(client) + const user = await selfEndpoint.getUser() setAuthState({ ...authState, @@ -85,8 +86,8 @@ const AuthProvider: FunctionComponent = ({children}) => { useEffect(() => { if (initialSessionToken) { const client = getClient(initialSessionToken) - const authenticationEndpoint = new AuthenticationEndpoint(client) - authenticationEndpoint.getUser() + const selfEndpoint = new SelfEndpoint(client) + selfEndpoint.getUser() .then(user => { setAuthState({ ...authState,