Skip to content

Instantly share code, notes, and snippets.

@newtonjob
Created March 21, 2025 14:38
Show Gist options
  • Save newtonjob/32163e987e355fe33ee40221663b843e to your computer and use it in GitHub Desktop.
Save newtonjob/32163e987e355fe33ee40221663b843e to your computer and use it in GitHub Desktop.
Magic login link using Laravel's `Password` broker
<?php
class MagicLoginLinkController extends Controller
{
public function create(Request $request, User $user)
{
$user->notify(new MagicLoginLink(Password::createToken($user)));
return response()->json(['message' => 'Magic login link sent.']);
}
public function store(Request $request, User $user): RedirectResponse
{
if (! Password::tokenExists($user, $request->token)) {
abort(404);
}
Auth::login($user);
Password::deleteToken($user);
return redirect()->intended('dashboard');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment