-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create barebones sequence for logging in
- Loading branch information
1 parent
3d6e82e
commit ec26dd1
Showing
5 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class LogInController extends Controller | ||
{ | ||
public function __invoke(Request $request): JsonResponse | ||
{ | ||
$request->validate([ | ||
'email' => ['required'], | ||
'password' => ['required'], | ||
]); | ||
|
||
if ( | ||
Auth::attempt([ | ||
'email' => $request->input('email'), | ||
'password' => $request->input('password'), | ||
]) | ||
) { | ||
// LOG ATTEMPT? | ||
return response() | ||
->json([ | ||
'token' => 'TOKEN_GOES_HERE', | ||
]); | ||
} else { | ||
// LOG ATTEMPT? | ||
return response() | ||
->json(['error' => 'UNABLE_TO_LOG_IN']); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup> | ||
// | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div class="max-w-5xl mx-auto my-10"> | ||
Hello world | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,44 @@ | ||
<script setup> | ||
// | ||
import axios from 'axios'; | ||
import { getCurrentInstance, ref } from 'vue'; | ||
const router = getCurrentInstance().proxy.$router; | ||
const email = ref(''); | ||
const password = ref(''); | ||
const logIn = () => { | ||
axios | ||
.post('/api/log-in', { email: email.value, password: password.value }) | ||
.then(response => { | ||
const json = response.data; | ||
if (json.token) { | ||
router.push('dashboard'); | ||
} | ||
if (json.error) { | ||
alert('Unable to log in'); | ||
} | ||
}) | ||
.catch(() => { | ||
alert('Unable to log in'); | ||
}); | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div class="max-w-sm mx-auto my-12"> | ||
<div class="p-5 bg-white border rounded-md space-y-5"> | ||
<div> | ||
<label class="block mb-1 text-sm text-gray-700">E-mail</label> | ||
<input class="w-full px-3 py-2 text-sm border rounded-md" type="email" /> | ||
<input class="w-full px-3 py-2 text-sm border rounded-md" type="email" v-model="email" /> | ||
</div> | ||
<div> | ||
<label class="block mb-1 text-sm text-gray-700">Password</label> | ||
<input class="w-full px-3 py-2 text-sm border rounded-md" type="password" /> | ||
<input class="w-full px-3 py-2 text-sm border rounded-md" type="password" v-model="password" @keyup.enter="logIn" /> | ||
</div> | ||
<button class="w-full py-2.5 hover:bg-blue-600 transition text-sm bg-blue-500 text-white rounded-md">Log in</button> | ||
<button class="w-full py-2.5 hover:bg-blue-600 transition text-sm bg-blue-500 text-white rounded-md" @click="logIn">Log in</button> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?php | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Api\LogInController; | ||
use Illuminate\Support\Facades\Route; | ||
|
||
// | ||
Route::post('/log-in', LogInController::class); |