[Login] Set env for Login / Logout
This commit is contained in:
parent
592788f2da
commit
945f11e5b0
|
|
@ -0,0 +1 @@
|
|||
VITE_AUTH_SERVICE_URL=http://localhost:8080/auth-service
|
||||
|
|
@ -1 +0,0 @@
|
|||
VITE_API_BASE_URL=http://192.168.0.1:3000
|
||||
|
|
@ -15,12 +15,13 @@ function App() {
|
|||
const handleLogin = async () => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
const url = `${import.meta.env.VITE_API_BASE_URL}/api/login`
|
||||
const url = `${import.meta.env.VITE_AUTH_SERVICE_URL}/auth/login`
|
||||
console.log('AUTH URL:', import.meta.env.VITE_AUTH_SERVICE_URL)
|
||||
const response = await fetchWithCred(url, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
username: 'alice',
|
||||
password: 'secret123'
|
||||
empLoginId: 'djhyoja',
|
||||
empLoginPassword: '2145'
|
||||
})
|
||||
})
|
||||
if (!response.ok) {
|
||||
|
|
@ -55,7 +56,7 @@ function App() {
|
|||
const handleLogout = async () => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
const url = `${import.meta.env.VITE_API_BASE_URL}/api/logout`
|
||||
const url = `${import.meta.env.VITE_AUTH_SERVICE_URL}/auth/logout`
|
||||
const response = await fetchWithCred(url, {
|
||||
method: 'POST',
|
||||
//...(csrfToken && { headers: { 'x-csrf-token': csrfToken }})
|
||||
|
|
@ -64,8 +65,7 @@ function App() {
|
|||
const data = await response.json()
|
||||
throw new ApiError(data.message || 'Failed to logout', response.status, data)
|
||||
}
|
||||
const result = await response.json()
|
||||
console.log('[Client] Logout response:', result)
|
||||
console.log('[Client] Logout response:', response)
|
||||
setIsLogin(false)
|
||||
} catch(err) {
|
||||
if (err instanceof ApiError) {
|
||||
|
|
@ -83,7 +83,7 @@ function App() {
|
|||
const handleProducts = async () => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
const url = `${import.meta.env.VITE_API_BASE_URL}/api/products`
|
||||
const url = `${import.meta.env.VITE_AUTH_SERVICE_URL}/api/products`
|
||||
const response = await fetchWithRefresh(url,{},{ retries: 5 }, csrfToken)
|
||||
if (!response.ok) {
|
||||
const data = await response.json()
|
||||
|
|
@ -107,7 +107,7 @@ function App() {
|
|||
const handleRefresh = async () => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
const url = `${import.meta.env.VITE_API_BASE_URL}/api/refresh`
|
||||
const url = `${import.meta.env.VITE_AUTH_SERVICE_URL}/auth/refresh`
|
||||
const response = await fetchWithCred(url,{
|
||||
method: 'POST',
|
||||
...(csrfToken && { headers: { 'x-csrf-token': csrfToken }})
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ export const fetchWithRefresh = async (url, options = {}, { retries = 1, timeout
|
|||
|
||||
if (response.status === 401) {
|
||||
console.log('Access token expired, trying refresh...')
|
||||
const refreshRes = await fetchWithCred(`${import.meta.env.VITE_API_BASE_URL}/api/refresh`,
|
||||
const refreshRes = await fetchWithCred(`${import.meta.env.VITE_AUTH_SERVICE_URL}/api/refresh`,
|
||||
{
|
||||
method: 'POST',
|
||||
...(csrfToken && { headers: { 'x-csrf-token': csrfToken }})
|
||||
|
|
|
|||
Loading…
Reference in New Issue