Skip to content

Commit c74b36d

Browse files
chore: wip
1 parent 8d86f00 commit c74b36d

File tree

3 files changed

+68
-17
lines changed

3 files changed

+68
-17
lines changed

app/Actions/LoginAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ export default new Action({
4141
return { token, team: teamValue }
4242
}
4343

44-
return 'fail'
44+
return { message: 'Incorrect email or password', status: 401 }
4545
},
4646
})

resources/views/auth/login.vue

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1+
<script setup>
2+
import { ref } from 'vue'
3+
4+
const router = useRouter()
5+
6+
// Reactive state for the email input
7+
const email = ref('')
8+
const password = ref('')
9+
10+
// Method to handle email submission
11+
async function login() {
12+
const body = {
13+
email: email.value,
14+
password: password.value,
15+
}
16+
17+
const url = 'http://localhost:3008/api/login'
18+
19+
const response = await fetch(url, {
20+
method: 'POST',
21+
headers: {
22+
'Content-Type': 'application/json',
23+
'Accept': 'application/json',
24+
},
25+
body: JSON.stringify(body),
26+
})
27+
28+
if (!response.ok) {
29+
const res = await response.json()
30+
}
31+
else {
32+
const data = await response.json()
33+
34+
localStorage.setItem('token', data.token)
35+
36+
router.push({ path: '/dashboard' })
37+
}
38+
39+
password.value = ''
40+
}
41+
</script>
42+
143
<template>
244
<div class="flex min-h-full flex-col justify-center py-12 sm:px-6 lg:px-8">
345
<div class="sm:mx-auto sm:w-full sm:max-w-md">
@@ -9,18 +51,18 @@
951

1052
<div class="mt-10 sm:mx-auto sm:w-full sm:max-w-[480px]">
1153
<div class="bg-white px-6 py-12 shadow sm:rounded-lg sm:px-12">
12-
<form class="space-y-6" action="#" method="POST">
54+
<div class="space-y-6">
1355
<div>
1456
<label for="email" class="block text-sm font-medium leading-6 text-gray-900">Email address</label>
1557
<div class="mt-2">
16-
<input id="email" name="email" type="email" autocomplete="email" required class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
58+
<input id="email" v-model="email" name="email" type="email" autocomplete="email" required class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
1759
</div>
1860
</div>
1961

2062
<div>
2163
<label for="password" class="block text-sm font-medium leading-6 text-gray-900">Password</label>
2264
<div class="mt-2">
23-
<input id="password" name="password" type="password" autocomplete="current-password" required class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
65+
<input id="password" v-model="password" name="password" type="password" autocomplete="current-password" required class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
2466
</div>
2567
</div>
2668

@@ -36,11 +78,11 @@
3678
</div>
3779

3880
<div>
39-
<button type="submit" class="flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">
81+
<button type="submit" class="flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" @click="login">
4082
Sign in
4183
</button>
4284
</div>
43-
</form>
85+
</div>
4486

4587
<div>
4688
<div class="relative mt-10">

storage/framework/core/router/src/server.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
218218
}
219219

220220
if (isObject(foundCallback) && foundCallback.status) {
221-
if (foundCallback.status === 422) {
222-
// biome-ignore lint/performance/noDelete: <explanation>
221+
if (foundCallback.status === 401) {
223222
delete foundCallback.status
224223

225224
return await new Response(JSON.stringify(foundCallback), {
@@ -228,13 +227,24 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
228227
'Access-Control-Allow-Origin': '*',
229228
'Access-Control-Allow-Headers': '*',
230229
},
231-
status: 422,
230+
status: 401,
232231
})
233232
}
234-
}
235233

236-
if (isObject(foundCallback) && foundCallback.status) {
237-
if (foundCallback.status === 401) {
234+
if (foundCallback.status === 403) {
235+
delete foundCallback.status
236+
return await new Response(JSON.stringify(foundCallback), {
237+
headers: {
238+
'Content-Type': 'json',
239+
'Access-Control-Allow-Origin': '*',
240+
'Access-Control-Allow-Headers': '*',
241+
},
242+
status: 403,
243+
})
244+
}
245+
246+
if (foundCallback.status === 422) {
247+
// biome-ignore lint/performance/noDelete: <explanation>
238248
delete foundCallback.status
239249

240250
return await new Response(JSON.stringify(foundCallback), {
@@ -243,21 +253,20 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
243253
'Access-Control-Allow-Origin': '*',
244254
'Access-Control-Allow-Headers': '*',
245255
},
246-
status: 401,
256+
status: 422,
247257
})
248258
}
249-
}
250259

251-
if (isObject(foundCallback) && foundCallback.status) {
252-
if (foundCallback.status === 403) {
260+
261+
if (foundCallback.status === 500) {
253262
delete foundCallback.status
254263
return await new Response(JSON.stringify(foundCallback), {
255264
headers: {
256265
'Content-Type': 'json',
257266
'Access-Control-Allow-Origin': '*',
258267
'Access-Control-Allow-Headers': '*',
259268
},
260-
status: 403,
269+
status: 500,
261270
})
262271
}
263272
}

0 commit comments

Comments
 (0)