feat: implement Telebirr payment API and types, enhance auth storage with token management

This commit is contained in:
Estifo77
2026-07-23 14:32:30 +03:00
parent 7191bc6791
commit 7e2186e758
8 changed files with 142 additions and 34 deletions

View File

@@ -42,7 +42,10 @@ const authSlice = createSlice({
state.isAuthenticated = false;
state.currentProfile = null;
authStorage.clear();
authStorage.clear();
},
setToken(state, action: PayloadAction<string>) {
state.token = action.payload;
authStorage.setToken(action.payload);
},
hydrateAuth(state) {
const token = authStorage.getToken();
@@ -67,5 +70,6 @@ export const {
clearCurrentProfile,
logout,
hydrateAuth,
setToken,
} = authSlice.actions;
export const authReducer = authSlice.reducer;

View File

@@ -1,8 +1,9 @@
import { authStorage } from './auth-storage';
import { authStorage } from "./auth-storage";
const BASE_API_URL =
(import.meta as { env?: Record<string, string> }).env?.['VITE_BASE_API_URL'] ??
'http://localhost:3001/api';
(import.meta as { env?: Record<string, string> }).env?.[
"VITE_BASE_API_URL"
] ?? "http://localhost:3001/api";
interface RefreshResponse {
token: string;
@@ -11,17 +12,17 @@ interface RefreshResponse {
export async function refreshAccessToken(): Promise<string> {
const refreshToken = authStorage.getRefreshToken();
if (!refreshToken) throw new Error('No refresh token available');
if (!refreshToken) throw new Error("No refresh token available");
const response = await fetch(`${BASE_API_URL}/auth/refresh`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
const response = await fetch(`${BASE_API_URL}/auth/refresh-token`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ refreshToken }),
});
if (!response.ok) {
authStorage.clear();
throw new Error('Token refresh failed');
throw new Error("Token refresh failed");
}
const data: RefreshResponse = await response.json();