Fix API authentication and identity service updates

This commit is contained in:
2026-09-02 18:19:34 +05:30
parent 54cd2a1e5f
commit a579da0f70
8 changed files with 1244 additions and 6 deletions
+63
View File
@@ -0,0 +1,63 @@
import os
filepath = r"c:\Users\Lenovo\Desktop\ai_pharma_frontend\src\services\api.ts"
with open(filepath, "r", encoding="utf-8") as f:
content = f.read()
# Replacement 1: Add API_KEY to axios.create
old_axios_create = """export const api = axios.create({
baseURL: API_BASE_URL,
headers: {
'Content-Type': 'application/json',
},
});"""
new_axios_create = """export const api = axios.create({
baseURL: API_BASE_URL,
headers: {
'Content-Type': 'application/json',
'x-api-key': import.meta.env.VITE_API_KEY || '',
},
});"""
content = content.replace(old_axios_create, new_axios_create)
# Replacement 2: update authenticate
old_auth = """ const response = await axios.post(`${API_BASE_URL}/auth/token`, {
grant_type: 'client_credentials',
client_id: 'jayam_web_ai',
client_secret: 'my_secret_key'
});"""
new_auth = """ const response = await axios.post(`${API_BASE_URL}/auth/token`, {
grant_type: 'client_credentials',
client_id: 'jayam_web_ai',
client_secret: 'my_secret_key'
}, {
headers: { 'x-api-key': import.meta.env.VITE_API_KEY || '' }
});"""
content = content.replace(old_auth, new_auth)
# Replacement 3: update loginPharmacist
old_login = """ const response = await axios.post(`${API_BASE_URL}/auth/login`, credentials);"""
new_login = """ const response = await axios.post(`${API_BASE_URL}/auth/login`, credentials, {
headers: { 'x-api-key': import.meta.env.VITE_API_KEY || '' }
});"""
content = content.replace(old_login, new_login)
# Replacement 4: update logoutPharmacist
old_logout = """ const response = await axios.post(`${API_BASE_URL}/auth/logout`);"""
new_logout = """ const response = await axios.post(`${API_BASE_URL}/auth/logout`, {}, {
headers: { 'x-api-key': import.meta.env.VITE_API_KEY || '' }
});"""
content = content.replace(old_logout, new_logout)
with open(filepath, "w", encoding="utf-8") as f:
f.write(content)
print("Updated api.ts")