feat(frontend): require center API key on login/auth calls
This commit is contained in:
@@ -19,7 +19,7 @@ type RefreshResponse = {
|
||||
tokenType: string
|
||||
}
|
||||
|
||||
function centerClient(centerApiBase: string) {
|
||||
function centerClient(centerApiBase: string, centerApiKey: string) {
|
||||
const client = axios.create({
|
||||
baseURL: centerApiBase,
|
||||
timeout: 10000,
|
||||
@@ -27,6 +27,7 @@ function centerClient(centerApiBase: string) {
|
||||
|
||||
client.interceptors.request.use((request) => {
|
||||
const requestId = crypto.randomUUID()
|
||||
request.headers['x-api-key'] = centerApiKey
|
||||
request.headers['x-request-id'] = requestId
|
||||
request.headers['x-client-name'] = 'fabric-frontend'
|
||||
return request
|
||||
@@ -35,16 +36,16 @@ function centerClient(centerApiBase: string) {
|
||||
return client
|
||||
}
|
||||
|
||||
export async function loginCenter(centerApiBase: string, payload: LoginPayload): Promise<AuthSession> {
|
||||
const res = await centerClient(centerApiBase).post<LoginResponse>('/auth/login', payload)
|
||||
return { ...res.data, centerApiBase }
|
||||
export async function loginCenter(centerApiBase: string, centerApiKey: string, payload: LoginPayload): Promise<AuthSession> {
|
||||
const res = await centerClient(centerApiBase, centerApiKey).post<LoginResponse>('/auth/login', payload)
|
||||
return { ...res.data, centerApiBase, centerApiKey }
|
||||
}
|
||||
|
||||
export async function refreshCenter(centerApiBase: string, refreshToken: string): Promise<RefreshResponse> {
|
||||
const res = await centerClient(centerApiBase).post<RefreshResponse>('/auth/refresh', { refreshToken })
|
||||
export async function refreshCenter(centerApiBase: string, centerApiKey: string, refreshToken: string): Promise<RefreshResponse> {
|
||||
const res = await centerClient(centerApiBase, centerApiKey).post<RefreshResponse>('/auth/refresh', { refreshToken })
|
||||
return res.data
|
||||
}
|
||||
|
||||
export async function logoutCenter(centerApiBase: string, refreshToken: string): Promise<void> {
|
||||
await centerClient(centerApiBase).post('/auth/logout', { refreshToken })
|
||||
export async function logoutCenter(centerApiBase: string, centerApiKey: string, refreshToken: string): Promise<void> {
|
||||
await centerClient(centerApiBase, centerApiKey).post('/auth/logout', { refreshToken })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user