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

@@ -1,13 +1,34 @@
export { AuthConfigProvider, useAuthConfig } from './lib/AuthConfig';
export type { AuthConfigValue } from './lib/AuthConfig';
export { AuthShell, BrandMark } from './lib/components/AuthShell';
export { ProtectedRoute } from './lib/components/ProtectedRoute';
export { LoginPage } from './lib/pages/LoginPage';
export { SignupPage } from './lib/pages/SignupPage';
export { ForgotPasswordPage } from './lib/pages/ForgotPasswordPage';
export { OTPVerificationPage } from './lib/pages/OTPVerificationPage';
export { authReducer, loginSuccess, setUser, setCurrentProfile, clearCurrentProfile, logout, hydrateAuth } from './lib/store/auth.slice';
export { signupReducer, setSignupData, setSignupStep, resetSignup } from './lib/store/signup.slice';
export { configureAuthStorage, authStorage } from './lib/utils/auth-storage';
export { refreshAccessToken } from './lib/utils/refresh-token';
export type { AuthUser, AuthState, LoginPayload, CurrentProfile, CurrentProfileAddress, CurrentProfileProfession } from './lib/types/auth.types';
export { AuthConfigProvider, useAuthConfig } from "./lib/AuthConfig";
export type { AuthConfigValue } from "./lib/AuthConfig";
export { AuthShell, BrandMark } from "./lib/components/AuthShell";
export { ProtectedRoute } from "./lib/components/ProtectedRoute";
export { LoginPage } from "./lib/pages/LoginPage";
export { SignupPage } from "./lib/pages/SignupPage";
export { ForgotPasswordPage } from "./lib/pages/ForgotPasswordPage";
export { OTPVerificationPage } from "./lib/pages/OTPVerificationPage";
export {
authReducer,
loginSuccess,
setUser,
setCurrentProfile,
clearCurrentProfile,
logout,
hydrateAuth,
setToken,
} from "./lib/store/auth.slice";
export {
signupReducer,
setSignupData,
setSignupStep,
resetSignup,
} from "./lib/store/signup.slice";
export { configureAuthStorage, authStorage } from "./lib/utils/auth-storage";
export { refreshAccessToken } from "./lib/utils/refresh-token";
export type {
AuthUser,
AuthState,
LoginPayload,
CurrentProfile,
CurrentProfileAddress,
CurrentProfileProfession,
} from "./lib/types/auth.types";

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();