[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 () => {
|
const handleLogin = async () => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true)
|
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, {
|
const response = await fetchWithCred(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
username: 'alice',
|
empLoginId: 'djhyoja',
|
||||||
password: 'secret123'
|
empLoginPassword: '2145'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|
@ -55,7 +56,7 @@ function App() {
|
||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true)
|
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, {
|
const response = await fetchWithCred(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
//...(csrfToken && { headers: { 'x-csrf-token': csrfToken }})
|
//...(csrfToken && { headers: { 'x-csrf-token': csrfToken }})
|
||||||
|
|
@ -64,8 +65,7 @@ function App() {
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
throw new ApiError(data.message || 'Failed to logout', response.status, data)
|
throw new ApiError(data.message || 'Failed to logout', response.status, data)
|
||||||
}
|
}
|
||||||
const result = await response.json()
|
console.log('[Client] Logout response:', response)
|
||||||
console.log('[Client] Logout response:', result)
|
|
||||||
setIsLogin(false)
|
setIsLogin(false)
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
if (err instanceof ApiError) {
|
if (err instanceof ApiError) {
|
||||||
|
|
@ -83,7 +83,7 @@ function App() {
|
||||||
const handleProducts = async () => {
|
const handleProducts = async () => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true)
|
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)
|
const response = await fetchWithRefresh(url,{},{ retries: 5 }, csrfToken)
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
|
|
@ -107,7 +107,7 @@ function App() {
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true)
|
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,{
|
const response = await fetchWithCred(url,{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
...(csrfToken && { headers: { 'x-csrf-token': csrfToken }})
|
...(csrfToken && { headers: { 'x-csrf-token': csrfToken }})
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ export const fetchWithRefresh = async (url, options = {}, { retries = 1, timeout
|
||||||
|
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
console.log('Access token expired, trying refresh...')
|
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',
|
method: 'POST',
|
||||||
...(csrfToken && { headers: { 'x-csrf-token': csrfToken }})
|
...(csrfToken && { headers: { 'x-csrf-token': csrfToken }})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue