Skip to content
Merged
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
39 changes: 39 additions & 0 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Actions\Fortify;

use App\Models\User;
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' => $input['password'],
]);
}
}
52 changes: 0 additions & 52 deletions app/Http/Controllers/Auth/RegisteredUserController.php

This file was deleted.

15 changes: 10 additions & 5 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,6 +39,7 @@ public function boot(): void
private function configureActions(): void
{
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
Fortify::createUsersUsing(CreateNewUser::class);
}

/**
Expand All @@ -47,22 +49,25 @@ private function configureViews(): void
{
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/verify-email', [
'status' => $request->session()->get('status'),
Fortify::resetPasswordView(fn (Request $request) => Inertia::render('auth/reset-password', [
'email' => $request->email,
'token' => $request->route('token'),
]));

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

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

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

Fortify::twoFactorChallengeView(fn () => Inertia::render('auth/two-factor-challenge'));

Fortify::confirmPasswordView(fn () => Inertia::render('auth/confirm-password'));
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
21 changes: 14 additions & 7 deletions resources/js/pages/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ import { Form, Head } from '@inertiajs/react';
interface LoginProps {
status?: string;
canResetPassword: boolean;
canRegister: boolean;
}

export default function Login({ status, canResetPassword }: LoginProps) {
export default function Login({
status,
canResetPassword,
canRegister,
}: LoginProps) {
return (
<AuthLayout
title="Log in to your account"
Expand Down Expand Up @@ -93,12 +98,14 @@ export default function Login({ status, canResetPassword }: LoginProps) {
</Button>
</div>

<div className="text-center text-sm text-muted-foreground">
Don't have an account?{' '}
<TextLink href={register()} tabIndex={5}>
Sign up
</TextLink>
</div>
{canRegister && (
<div className="text-center text-sm text-muted-foreground">
Don't have an account?{' '}
<TextLink href={register()} tabIndex={5}>
Sign up
</TextLink>
</div>
)}
</>
)}
</Form>
Expand Down
4 changes: 2 additions & 2 deletions resources/js/pages/auth/register.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import RegisteredUserController from '@/actions/App/Http/Controllers/Auth/RegisteredUserController';
import { login } from '@/routes';
import { store } from '@/routes/register';
import { Form, Head } from '@inertiajs/react';

import InputError from '@/components/input-error';
Expand All @@ -18,7 +18,7 @@ export default function Register() {
>
<Head title="Register" />
<Form
{...RegisteredUserController.store.form()}
{...store.form()}
resetOnSuccess={['password', 'password_confirmation']}
disableWhileProcessing
className="flex flex-col gap-6"
Expand Down
20 changes: 13 additions & 7 deletions resources/js/pages/welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { dashboard, login, register } from '@/routes';
import { type SharedData } from '@/types';
import { Head, Link, usePage } from '@inertiajs/react';

export default function Welcome() {
export default function Welcome({
canRegister = true,
}: {
canRegister?: boolean;
}) {
const { auth } = usePage<SharedData>().props;

return (
Expand Down Expand Up @@ -32,12 +36,14 @@ export default function Welcome() {
>
Log in
</Link>
<Link
href={register()}
className="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]"
>
Register
</Link>
{canRegister && (
<Link
href={register()}
className="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]"
>
Register
</Link>
)}
</>
)}
</nav>
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,9 +2,12 @@

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::middleware(['auth', 'verified'])->group(function () {
Expand All @@ -14,4 +17,3 @@
});

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