Some checks failed
Run Tests / unit-tests (pull_request) Has been cancelled
Run Tests / cypress-tests (chrome) (pull_request) Has been cancelled
Run Tests / cypress-tests (edge) (pull_request) Has been cancelled
Run Tests / cypress-tests (firefox) (pull_request) Has been cancelled
Run Tests / install (pull_request) Has been cancelled
Run Tests / install (push) Failing after 7m36s
Run Tests / unit-tests (push) Has been skipped
Run Tests / cypress-tests (chrome) (push) Has been skipped
Run Tests / cypress-tests (edge) (push) Has been skipped
Run Tests / cypress-tests (firefox) (push) Has been skipped
21 lines
728 B
TypeScript
21 lines
728 B
TypeScript
import axios from 'axios'
|
|
|
|
const API_BASE = 'http://localhost:3000' // Update with your backend address
|
|
|
|
export const register = async (username: string, password: string) => {
|
|
return axios.post(`${API_BASE}/register`, { username, password })
|
|
}
|
|
|
|
export const login = async (username: string, password: string) => {
|
|
const response = await axios.post(`${API_BASE}/login`, { username, password })
|
|
const token = response.data.token
|
|
localStorage.setItem('token', token) // Save token for authenticated requests
|
|
return token
|
|
}
|
|
|
|
export const getProtectedData = async () => {
|
|
const token = localStorage.getItem('token')
|
|
return axios.get(`${API_BASE}/protected`, {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
})
|
|
}
|