|
|
|
@ -1,5 +1,4 @@ |
|
|
|
import axios from 'axios' |
|
|
|
import { LOCAL_STORAGE_KEY } from '../shared/constants' |
|
|
|
import axiosInstance from '../lib/axiosInstance' |
|
|
|
import { |
|
|
|
GoogleLoginRequestPayload, |
|
|
|
LoginRequestPayload, |
|
|
|
@ -8,51 +7,45 @@ import { |
|
|
|
RegisterResponse, |
|
|
|
SendSMSRequestPayload, |
|
|
|
} from './types' |
|
|
|
const BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL |
|
|
|
|
|
|
|
if (typeof localStorage !== 'undefined') |
|
|
|
axios.defaults.headers.common[ |
|
|
|
'Authorization' |
|
|
|
] = `Bearer ${localStorage.getItem(LOCAL_STORAGE_KEY.TOKEN)}` |
|
|
|
|
|
|
|
export const loginRequest = async ( |
|
|
|
payload: LoginRequestPayload |
|
|
|
): Promise<LoginResponse> => { |
|
|
|
const res = await axios.post(`${BASE_URL}/auth/login`, payload) |
|
|
|
const res = await axiosInstance.post(`/auth/login`, payload) |
|
|
|
return res.data.data |
|
|
|
} |
|
|
|
|
|
|
|
export const loginWithGoogleRequest = async ( |
|
|
|
payload: GoogleLoginRequestPayload |
|
|
|
): Promise<LoginResponse> => { |
|
|
|
const res = await axios.post(`${BASE_URL}/auth/google-login`, payload) |
|
|
|
const res = await axiosInstance.post(`/auth/google-login`, payload) |
|
|
|
return res.data.data |
|
|
|
} |
|
|
|
|
|
|
|
export const registerRequest = async ( |
|
|
|
payload: RegisterRequestPayload |
|
|
|
): Promise<RegisterResponse> => { |
|
|
|
const res = await axios.post(`${BASE_URL}/auth/register`, payload) |
|
|
|
const res = await axiosInstance.post(`/auth/register`, payload) |
|
|
|
return res.data.data |
|
|
|
} |
|
|
|
|
|
|
|
export const generateApiKeyRequest = async () => { |
|
|
|
const res = await axios.post(`${BASE_URL}/auth/api-keys`, {}) |
|
|
|
const res = await axiosInstance.post(`/auth/api-keys`, {}) |
|
|
|
return res.data.data |
|
|
|
} |
|
|
|
|
|
|
|
export const getApiKeyListRequest = async () => { |
|
|
|
const res = await axios.get(`${BASE_URL}/auth/api-keys`) |
|
|
|
const res = await axiosInstance.get(`/auth/api-keys`) |
|
|
|
return res.data.data |
|
|
|
} |
|
|
|
|
|
|
|
export const deleteApiKeyRequest = async (id: string) => { |
|
|
|
const res = await axios.delete(`${BASE_URL}/auth/api-keys/${id}`) |
|
|
|
const res = await axiosInstance.delete(`/auth/api-keys/${id}`) |
|
|
|
return res.data.data |
|
|
|
} |
|
|
|
|
|
|
|
export const getDeviceListRequest = async () => { |
|
|
|
const res = await axios.get(`${BASE_URL}/gateway/devices`) |
|
|
|
const res = await axiosInstance.get(`/gateway/devices`) |
|
|
|
return res.data.data |
|
|
|
} |
|
|
|
|
|
|
|
@ -60,8 +53,8 @@ export const sendSMSRequest = async ( |
|
|
|
deviceId: string, |
|
|
|
payload: SendSMSRequestPayload |
|
|
|
) => { |
|
|
|
const res = await axios.post( |
|
|
|
`${BASE_URL}/gateway/devices/${deviceId}/sendSMS`, |
|
|
|
const res = await axiosInstance.post( |
|
|
|
`/gateway/devices/${deviceId}/sendSMS`, |
|
|
|
payload |
|
|
|
) |
|
|
|
return res.data.data |
|
|
|
|