mirror of
https://github.com/sigmasternchen/threadule
synced 2025-03-14 23:59:00 +00:00
feat: switched frontend to new self endpoint
This commit is contained in:
parent
035207f012
commit
254a9440a8
3 changed files with 22 additions and 9 deletions
|
@ -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<LoginResponse> {
|
||||
return this.post<LoginParams, LoginResponse>(API_PREFIX, params)
|
||||
}
|
||||
|
||||
public async getUser(): Promise<User> {
|
||||
return this.get<User>(API_PREFIX)
|
||||
}
|
||||
}
|
||||
|
||||
export default AuthenticationEndpoint
|
17
frontend/src/api/endpoints/SelfEndpoint.ts
Normal file
17
frontend/src/api/endpoints/SelfEndpoint.ts
Normal 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
|
|
@ -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<AuthProviderProps> = ({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<AuthProviderProps> = ({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,
|
||||
|
|
Loading…
Reference in a new issue