feat: add api to connect user completion form to backend

This commit is contained in:
Koosha Lahouti
2025-08-05 18:59:54 -07:00
parent 0f9ef06742
commit 3e23fae993
3 changed files with 66 additions and 37 deletions

34
src/lib/authToken.ts Normal file
View File

@@ -0,0 +1,34 @@
// src/lib/authService.ts
import axios from 'axios';
export interface TokenResponse {
access_token: string;
expires_in: number;
refresh_token: string;
}
const authClient = axios.create({
baseURL: 'https://account.business-harmony.com',
timeout: 10000,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
});
export async function loginWithPassword(
username: string,
password: string,
): Promise<TokenResponse> {
const body = new URLSearchParams();
body.set('grant_type', 'password');
body.set('username', username);
body.set('password', password);
body.set('client_id', 'harmony_identity');
body.set('scope', 'openid harmony_identity profile offline_access');
const { data } = await authClient.post<TokenResponse>(
'/connect/token',
body.toString(),
);
localStorage.setItem('authToken', data.access_token);
return data;
}