VORKOUT-6 #11
@ -1,5 +1,5 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Access, Auth } from '../types/auth';
|
import { Auth, Tokens } from '../types/auth';
|
||||||
import { User } from '../types/user';
|
import { User } from '../types/user';
|
||||||
import { AuthService } from '../services/authService';
|
import { AuthService } from '../services/authService';
|
||||||
import axiosRetry from 'axios-retry';
|
import axiosRetry from 'axios-retry';
|
||||||
@ -70,23 +70,16 @@ base.interceptors.response.use(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
interface newAccess {
|
|
||||||
accessToken: string;
|
|
||||||
refreshToken: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const api = {
|
const api = {
|
||||||
// auth
|
// auth
|
||||||
// async login(auth: Auth): Promise<Access> {
|
async login(auth: Auth): Promise<Tokens> {
|
||||||
async login(auth: Auth): Promise<newAccess> {
|
const response = await base.post<Tokens>('/auth', auth);
|
||||||
// const response = (await base.post) <Access> ('/auth', auth);
|
|
||||||
const response = await base.post<newAccess>('/auth', auth);
|
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
async refreshToken(): Promise<Access> {
|
async refreshToken(): Promise<Tokens> {
|
||||||
const token = localStorage.getItem('refreshToken');
|
const token = localStorage.getItem('refreshToken');
|
||||||
const response = await base.post<Access>(
|
const response = await base.post<Tokens>(
|
||||||
'/auth/refresh',
|
'/auth/refresh',
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@ export class AuthService {
|
|||||||
static async login(auth: Auth) {
|
static async login(auth: Auth) {
|
||||||
const token = await api.login(auth);
|
const token = await api.login(auth);
|
||||||
useAuthStore.getState().setAccessToken(token.accessToken);
|
useAuthStore.getState().setAccessToken(token.accessToken);
|
||||||
localStorage.setItem('refreshToken', token.refreshToken);
|
localStorage.setItem('refreshToken', token.refreshToken as string);
|
||||||
await UserService.getProfile().then((user) => {
|
await UserService.getProfile().then((user) => {
|
||||||
useUserStore.getState().setUser(user);
|
useUserStore.getState().setUser(user);
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { components } from './openapi-types';
|
import { components } from './openapi-types';
|
||||||
|
|
||||||
export type Auth = components['schemas']['Auth'];
|
export type Auth = components['schemas']['Auth'];
|
||||||
export type Access = components['schemas']['Access'];
|
export type Tokens = components['schemas']['Tokens'];
|
||||||
|
@ -120,11 +120,6 @@ export interface paths {
|
|||||||
export type webhooks = Record<string, never>;
|
export type webhooks = Record<string, never>;
|
||||||
export interface components {
|
export interface components {
|
||||||
schemas: {
|
schemas: {
|
||||||
/** Access */
|
|
||||||
Access: {
|
|
||||||
/** Accesstoken */
|
|
||||||
accessToken: string;
|
|
||||||
};
|
|
||||||
/** AccountKeyring */
|
/** AccountKeyring */
|
||||||
AccountKeyring: {
|
AccountKeyring: {
|
||||||
/** Ownerid */
|
/** Ownerid */
|
||||||
@ -219,6 +214,13 @@ export interface components {
|
|||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
KeyType: "PASSWORD" | "ACCESS_TOKEN" | "REFRESH_TOKEN" | "API_KEY";
|
KeyType: "PASSWORD" | "ACCESS_TOKEN" | "REFRESH_TOKEN" | "API_KEY";
|
||||||
|
/** Tokens */
|
||||||
|
Tokens: {
|
||||||
|
/** Accesstoken */
|
||||||
|
accessToken: string;
|
||||||
|
/** Refreshtoken */
|
||||||
|
refreshToken?: string | null;
|
||||||
|
};
|
||||||
/** User */
|
/** User */
|
||||||
User: {
|
User: {
|
||||||
/** Id */
|
/** Id */
|
||||||
@ -305,7 +307,7 @@ export interface operations {
|
|||||||
[name: string]: unknown;
|
[name: string]: unknown;
|
||||||
};
|
};
|
||||||
content: {
|
content: {
|
||||||
"application/json": components["schemas"]["Access"];
|
"application/json": components["schemas"]["Tokens"];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
/** @description Validation Error */
|
/** @description Validation Error */
|
||||||
@ -334,7 +336,7 @@ export interface operations {
|
|||||||
[name: string]: unknown;
|
[name: string]: unknown;
|
||||||
};
|
};
|
||||||
content: {
|
content: {
|
||||||
"application/json": components["schemas"]["Access"];
|
"application/json": components["schemas"]["Tokens"];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user