Skip to content
Snippets Groups Projects
Commit 1b6cbca4 authored by michael.minelli's avatar michael.minelli
Browse files

DojoBackendManager => Add login and refreshTokens functions

parent 9b3278eb
Branches
No related tags found
No related merge requests found
...@@ -7,6 +7,8 @@ import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig ...@@ -7,6 +7,8 @@ import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig
import Assignment from '../sharedByClients/models/Assignment'; import Assignment from '../sharedByClients/models/Assignment';
import DojoBackendResponse from '../shared/types/Dojo/DojoBackendResponse'; import DojoBackendResponse from '../shared/types/Dojo/DojoBackendResponse';
import Exercise from '../sharedByClients/models/Exercise'; import Exercise from '../sharedByClients/models/Exercise';
import GitlabToken from '../shared/types/Gitlab/GitlabToken';
import User from '../sharedByClients/models/User';
class DojoBackendManager { class DojoBackendManager {
...@@ -14,6 +16,26 @@ class DojoBackendManager { ...@@ -14,6 +16,26 @@ class DojoBackendManager {
return `${ ClientsSharedConfig.apiURL }${ route }`; return `${ ClientsSharedConfig.apiURL }${ route }`;
} }
public async login(gitlabTokens: GitlabToken): Promise<User | undefined> {
try {
return (await axios.post<DojoBackendResponse<User>>(this.getApiUrl(ApiRoute.LOGIN), {
accessToken : gitlabTokens.access_token,
refreshToken: gitlabTokens.refresh_token
})).data.data;
} catch ( error ) {
return undefined;
}
}
public async refreshTokens(refreshToken: string): Promise<GitlabToken> {
return (await axios.post<DojoBackendResponse<GitlabToken>>(this.getApiUrl(ApiRoute.REFRESH_TOKENS), {
refreshToken: refreshToken
})).data.data;
}
public async getAssignment(nameOrUrl: string): Promise<Assignment | undefined> { public async getAssignment(nameOrUrl: string): Promise<Assignment | undefined> {
try { try {
return (await axios.get<DojoBackendResponse<Assignment>>(this.getApiUrl(ApiRoute.ASSIGNMENT_GET).replace('{{nameOrUrl}}', encodeURIComponent(nameOrUrl)))).data.data; return (await axios.get<DojoBackendResponse<Assignment>>(this.getApiUrl(ApiRoute.ASSIGNMENT_GET).replace('{{nameOrUrl}}', encodeURIComponent(nameOrUrl)))).data.data;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment