feat: switched frontend to new self endpoint

This commit is contained in:
overflowerror 2021-08-22 18:35:53 +02:00
parent 035207f012
commit 254a9440a8
3 changed files with 22 additions and 9 deletions

View file

@ -1,7 +1,6 @@
import Endpoint from "./Endpoint"; import Endpoint from "./Endpoint";
import {Client} from "../client"; import {Client} from "../client";
import {LoginParams, LoginResponse} from "../entities/login"; import {LoginParams, LoginResponse} from "../entities/login";
import User from "../entities/User";
const API_PREFIX = "/api/authentication/" const API_PREFIX = "/api/authentication/"
@ -13,10 +12,6 @@ class AuthenticationEndpoint extends Endpoint {
public async login(params: LoginParams): Promise<LoginResponse> { public async login(params: LoginParams): Promise<LoginResponse> {
return this.post<LoginParams, LoginResponse>(API_PREFIX, params) return this.post<LoginParams, LoginResponse>(API_PREFIX, params)
} }
public async getUser(): Promise<User> {
return this.get<User>(API_PREFIX)
}
} }
export default AuthenticationEndpoint export default AuthenticationEndpoint

View file

@ -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<User> {
return this.get<User>(API_PREFIX)
}
}
export default AuthenticationEndpoint

View file

@ -3,6 +3,7 @@ import AuthenticationEndpoint from "../api/endpoints/AuthenticationEndpoint";
import {Client, getClient} from "../api/client"; import {Client, getClient} from "../api/client";
import User from "../api/entities/User"; import User from "../api/entities/User";
import {Backdrop, CircularProgress} from "@material-ui/core"; import {Backdrop, CircularProgress} from "@material-ui/core";
import SelfEndpoint from "../api/endpoints/SelfEndpoint";
type AuthState = { type AuthState = {
loggedIn: boolean loggedIn: boolean
@ -55,8 +56,8 @@ const AuthProvider: FunctionComponent<AuthProviderProps> = ({children}) => {
const client = getClient(response.token) const client = getClient(response.token)
// local new authenticationEndpoint // local new authenticationEndpoint
authenticationEndpoint = new AuthenticationEndpoint(client) const selfEndpoint = new SelfEndpoint(client)
const user = await authenticationEndpoint.getUser() const user = await selfEndpoint.getUser()
setAuthState({ setAuthState({
...authState, ...authState,
@ -85,8 +86,8 @@ const AuthProvider: FunctionComponent<AuthProviderProps> = ({children}) => {
useEffect(() => { useEffect(() => {
if (initialSessionToken) { if (initialSessionToken) {
const client = getClient(initialSessionToken) const client = getClient(initialSessionToken)
const authenticationEndpoint = new AuthenticationEndpoint(client) const selfEndpoint = new SelfEndpoint(client)
authenticationEndpoint.getUser() selfEndpoint.getUser()
.then(user => { .then(user => {
setAuthState({ setAuthState({
...authState, ...authState,