feat: frontend auth flow (login, user management, audit logs, route guards)
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
import client from './client'
|
||||
|
||||
export const getAuditLogs = (params?: { page?: number; page_size?: number; action?: string }) =>
|
||||
client.get('/audit', { params })
|
||||
@@ -0,0 +1,12 @@
|
||||
import client from './client'
|
||||
|
||||
export const login = (username: string, password: string) =>
|
||||
client.post('/auth/login', { username, password })
|
||||
|
||||
export const register = (data: { username: string; email: string; password: string }) =>
|
||||
client.post('/auth/register', data)
|
||||
|
||||
export const refresh = () => client.post('/auth/refresh')
|
||||
|
||||
export const changePassword = (data: { old_password: string; new_password: string }) =>
|
||||
client.post('/auth/change-password', data)
|
||||
@@ -0,0 +1,27 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const client = axios.create({
|
||||
baseURL: '/api/v1',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
|
||||
client.interceptors.request.use((config) => {
|
||||
const token = localStorage.getItem('access_token')
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
})
|
||||
|
||||
client.interceptors.response.use(
|
||||
(res) => res,
|
||||
(err) => {
|
||||
if (err.response?.status === 401) {
|
||||
localStorage.removeItem('access_token')
|
||||
window.location.href = '/login'
|
||||
}
|
||||
return Promise.reject(err)
|
||||
},
|
||||
)
|
||||
|
||||
export default client
|
||||
@@ -0,0 +1,11 @@
|
||||
import client from './client'
|
||||
|
||||
export const getUsers = (params?: { page?: number; page_size?: number }) =>
|
||||
client.get('/users', { params })
|
||||
|
||||
export const getUser = (id: string) => client.get(`/users/${id}`)
|
||||
|
||||
export const updateUser = (id: string, data: { role?: string; is_active?: boolean }) =>
|
||||
client.patch(`/users/${id}`, data)
|
||||
|
||||
export const approveUser = (id: string) => client.post(`/users/${id}/approve`)
|
||||
Reference in New Issue
Block a user