Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Actions\Fortify;

use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\CreatesNewUsers;

class CreateNewUser implements CreatesNewUsers
{
use PasswordValidationRules;

/**
* Validate and create a newly registered user.
*
* @param array<string, string> $input
*/
public function create(array $input): User
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => [
'required',
'string',
'email',
'max:255',
Rule::unique(User::class),
],
'password' => $this->passwordRules(),
])->validate();

return User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
}
}
53 changes: 0 additions & 53 deletions app/Http/Controllers/Auth/RegisteredUserController.php

This file was deleted.

17 changes: 10 additions & 7 deletions app/Providers/FortifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use App\Actions\Fortify\CreateNewUser;
use App\Actions\Fortify\ResetUserPassword;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -38,33 +39,35 @@ public function boot(): void
private function configureActions(): void
{
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
Fortify::createUsersUsing(CreateNewUser::class);
}

/**
* Configure Fortify views.
*/
private function configureViews(): void
{
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);

Fortify::loginView(fn (Request $request) => Inertia::render('auth/Login', [
'canResetPassword' => Features::enabled(Features::resetPasswords()),
'canRegister' => Features::enabled(Features::registration()),
'status' => $request->session()->get('status'),
]));

Fortify::verifyEmailView(fn (Request $request) => Inertia::render('auth/VerifyEmail', [
'status' => $request->session()->get('status'),
Fortify::resetPasswordView(fn (Request $request) => Inertia::render('auth/ResetPassword', [
'email' => $request->email,
'token' => $request->route('token'),
]));

Fortify::requestPasswordResetLinkView(fn (Request $request) => Inertia::render('auth/ForgotPassword', [
'status' => $request->session()->get('status'),
]));

Fortify::resetPasswordView(fn (Request $request) => Inertia::render('auth/ResetPassword', [
'email' => $request->email,
'token' => $request->route('token'),
Fortify::verifyEmailView(fn (Request $request) => Inertia::render('auth/VerifyEmail', [
'status' => $request->session()->get('status'),
]));

Fortify::registerView(fn () => Inertia::render('auth/Register'));

Fortify::twoFactorChallengeView(fn () => Inertia::render('auth/TwoFactorChallenge'));

Fortify::confirmPasswordView(fn () => Inertia::render('auth/ConfirmPassword'));
Expand Down
2 changes: 1 addition & 1 deletion config/fortify.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
*/

'features' => [
// Features::registration(),
Features::registration(),
Features::resetPasswords(),
Features::emailVerification(),
Features::twoFactorAuthentication([
Expand Down
10 changes: 10 additions & 0 deletions resources/js/pages/Welcome.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<script setup lang="ts">
import { dashboard, login, register } from '@/routes';
import { Head, Link } from '@inertiajs/vue3';

withDefaults(
defineProps<{
canRegister: boolean;
}>(),
{
canRegister: true,
},
);
</script>

<template>
Expand Down Expand Up @@ -30,6 +39,7 @@ import { Head, Link } from '@inertiajs/vue3';
Log in
</Link>
<Link
v-if="canRegister"
:href="register()"
class="inline-block rounded-sm border border-[#19140035] px-5 py-1.5 text-sm leading-normal text-[#1b1b18] hover:border-[#1915014a] dark:border-[#3E3E3A] dark:text-[#EDEDEC] dark:hover:border-[#62605b]"
>
Expand Down
6 changes: 5 additions & 1 deletion resources/js/pages/auth/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { LoaderCircle } from 'lucide-vue-next';
defineProps<{
status?: string;
canResetPassword: boolean;
canRegister: boolean;
}>();
</script>

Expand Down Expand Up @@ -100,7 +101,10 @@ defineProps<{
</Button>
</div>

<div class="text-center text-sm text-muted-foreground">
<div
class="text-center text-sm text-muted-foreground"
v-if="canRegister"
>
Don't have an account?
<TextLink :href="register()" :tabindex="5">Sign up</TextLink>
</div>
Expand Down
4 changes: 2 additions & 2 deletions resources/js/pages/auth/Register.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script setup lang="ts">
import RegisteredUserController from '@/actions/App/Http/Controllers/Auth/RegisteredUserController';
import InputError from '@/components/InputError.vue';
import TextLink from '@/components/TextLink.vue';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import AuthBase from '@/layouts/AuthLayout.vue';
import { login } from '@/routes';
import { store } from '@/routes/register';
import { Form, Head } from '@inertiajs/vue3';
import { LoaderCircle } from 'lucide-vue-next';
</script>
Expand All @@ -19,7 +19,7 @@ import { LoaderCircle } from 'lucide-vue-next';
<Head title="Register" />

<Form
v-bind="RegisteredUserController.store.form()"
v-bind="store.form()"
:reset-on-success="['password', 'password_confirmation']"
v-slot="{ errors, processing }"
class="flex flex-col gap-6"
Expand Down
12 changes: 0 additions & 12 deletions routes/auth.php

This file was deleted.

6 changes: 4 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use Laravel\Fortify\Features;

Route::get('/', function () {
return Inertia::render('Welcome');
return Inertia::render('Welcome', [
'canRegister' => Features::enabled(Features::registration()),
]);
})->name('home');

Route::get('dashboard', function () {
return Inertia::render('Dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');

require __DIR__.'/settings.php';
require __DIR__.'/auth.php';