Implement login page with email/password authentication #69

Merged
FernandoJVideira merged 6 commits from feature/login-page into develop 2025-12-22 17:08:38 +00:00
5 changed files with 50 additions and 33 deletions
Showing only changes of commit a566387998 - Show all commits
+9
View File
@@ -0,0 +1,9 @@
### Get All Students
POST http://localhost:8000/api/login
content-Type: application/json
Accept: application/json
{
"email": "[email protected]",
"password": "123"
}
+7 -7
View File
@@ -64,16 +64,16 @@ const formData = ref({
const handleSubmit = async () => {
console.log(formData, authStore)
toast.promise(authStore.login(formData.value), {
const promise = authStore.login(formData.value)
toast.promise(promise, {
loading: 'Calling API',
success: (data) => {
return `Login Sucessfull - ${data?.name}`
success: (user) => {
router.push('/')
return `Login Successful - ${user.name}`
},
error: (data) => `[API] Error - ${data?.response?.data?.message}`
error: (error) =>
error.response?.data?.message
})
router.push('/')
}
</script>
+5 -1
View File
@@ -16,11 +16,15 @@ export const useAPIStore = defineStore('api', () => {
},
})
// AUTH
const postLogin = async (credentials) => {
const response = await axios.post(`${API_BASE_URL}/login`, credentials)
if (!response.data.token) throw response
token.value = response.data.token
axios.defaults.headers.common['Authorization'] = `Bearer ${token.value}`
return response
}
const postLogout = async () => {
await axios.post(`${API_BASE_URL}/logout`)
+5 -7
View File
@@ -30,14 +30,12 @@ export const useAuthStore = defineStore('auth', () => {
}
const login = async (credentials) => {
await apiStore.postLogin(credentials)
const response = await apiStore.getAuthUser()
const jwtToken = response
const user = response.data
const loginResp = await apiStore.postLogin(credentials)
const userResp = await apiStore.getAuthUser()
const jwtToken = loginResp.data.token
setToken(jwtToken)
currentUser.value = response.data
return response.data
currentUser.value = userResp.data
return userResp.data
}
const logout = async () => {
+6
View File
@@ -2,18 +2,24 @@ import { defineStore } from 'pinia'
import { inject } from 'vue'
export const useSocketStore = defineStore('socket', () => {
try {
const socket = inject('socket')
const handleConnection = () => {
try {
socket.on('connect', () => {
console.log(`[Socket] Connected -- ${socket.id}`)
})
socket.on('disconnect', () => {
console.log(`[Socket] Disconnected -- ${socket.id}`)
})
} catch (error) {}
}
return {
handleConnection,
}
} catch (error) {
}
})