Skip to content

Commit 96d65bc

Browse files
rename envs
1 parent c48cc83 commit 96d65bc

8 files changed

Lines changed: 16 additions & 40 deletions

File tree

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"Bash(npm run:*)",
88
"Bash(node -e \"const pkg = require\\('./node_modules/focus-trap-react/package.json'\\); console.log\\(pkg.version, pkg.main, pkg.module, pkg.exports\\)\")",
99
"Bash(node -e \"const m = require\\('focus-trap-react'\\); console.log\\(Object.keys\\(m\\)\\)\")",
10-
"Bash(node -e \"require\\('focus-trap'\\)\")"
10+
"Bash(node -e \"require\\('focus-trap'\\)\")",
11+
"Bash(npm uninstall:*)"
1112
]
1213
}
1314
}

.env

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
VITE_API_URL=http://localhost:3333
22

33
# Credenciais do único usuário do sistema
4-
VITE_LOGIN_USERNAME=admin
5-
VITE_LOGIN_PASSWORD=senha123
4+
LOGIN_USERNAME=admin
5+
LOGIN_PASSWORD=senha123
66

77
# Secret para assinar o JWT (deve ser igual ao secret do backend)
8-
VITE_JWT_SECRET=change-me-in-production
8+
JWT_SECRET=change-me-in-production

package-lock.json

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"class-variance-authority": "^0.7.1",
1919
"clsx": "^2.1.1",
2020
"focus-trap-react": "^12.0.0",
21-
"jose": "^6.2.2",
2221
"lucide-react": "^0.577.0",
2322
"react": "^18.3.1",
2423
"react-dom": "^18.3.1",

src/features/auth/pages/LoginPage/index.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ import { Package } from 'lucide-react'
22
import { useState } from 'react'
33
import { useNavigate } from 'react-router-dom'
44

5+
import { login } from '@/shared/api/auth-api'
56
import { Button } from '@/shared/components/ui/Button'
67
import { Input } from '@/shared/components/ui/Input'
78
import { setToken } from '@/shared/utils/auth'
8-
import { generateToken } from '@/shared/utils/jwt'
9-
10-
const VALID_USERNAME = import.meta.env.VITE_LOGIN_USERNAME ?? ''
11-
const VALID_PASSWORD = import.meta.env.VITE_LOGIN_PASSWORD ?? ''
129

1310
export default function LoginPage() {
1411
const navigate = useNavigate()
@@ -20,19 +17,14 @@ export default function LoginPage() {
2017
const handleSubmit = async (e: React.FormEvent) => {
2118
e.preventDefault()
2219
setError(null)
23-
24-
if (username !== VALID_USERNAME || password !== VALID_PASSWORD) {
25-
setError('Usuário ou senha inválidos.')
26-
return
27-
}
28-
2920
setLoading(true)
21+
3022
try {
31-
const token = await generateToken()
23+
const { token } = await login(username, password)
3224
setToken(token)
3325
navigate('/', { replace: true })
3426
} catch {
35-
setError('Erro ao gerar sessão. Tente novamente.')
27+
setError('Usuário ou senha inválidos.')
3628
} finally {
3729
setLoading(false)
3830
}

src/shared/api/auth-api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { api } from './client'
2+
3+
export async function login(username: string, password: string): Promise<{ token: string }> {
4+
const { data } = await api.post<{ token: string }>('/auth/login', { username, password })
5+
return data
6+
}

src/shared/api/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ api.interceptors.request.use((config) => {
1717
api.interceptors.response.use(
1818
(response) => response,
1919
(error) => {
20-
if (error.response?.status === 401) {
20+
if (error.response?.status === 401 && window.location.pathname !== '/login') {
2121
clearToken()
2222
window.location.href = '/login'
2323
}

src/shared/utils/jwt.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)