-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEAT(auth): implement magic link authentication #642
Merged
Merged
Conversation
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
- Add MagicLinkController to handle magic link requests - Add MagicLinkEmail mailable for sending magic link emails - Add magic_link.blade.php template for the email content - Add unit tests for the magic link functionality - Update routes/api.php to include the magic link endpoint - Add migration to add magic_link_token and magic_link_expires_at columns to users table"
- Update MagicLinkController to return consistent error response"
- Added JSON documentation for the new /api/v1/auth/magic-link POST endpoint. - Included request body, responses (200, 400, 404, 500), and example payloads. - Updated the API documentation to reflect the new passwordless authentication feature.
bhimbho
requested changes
Mar 1, 2025
- Added endpoint `/api/v1/auth/magic-link/verify` to complete passwordless login implementation - Implemented `MagicLinkController` to handle magic link verification requests - Updated `routes/api.php` to include magic link verifiacation endpoint - Included unit tests for magic link verification functionality FIX(auth): resolve issues in magic link handling - Fixed missing email variable in `MagicLinkEmail` constructor - Ensured magic link includes both email and token in the URL - Fixed incorrect route in `magic_link.blade.php` template - Handled email sending failure with proper error responses
bhimbho
approved these changes
Mar 2, 2025
bhimbho
approved these changes
Mar 2, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a complete magic link authentication mechanism, allowing users to sign in without a password by receiving a one-time login token via email. In addition to the initial
send-magic-link
endpoint, this PR now includes a newverify-magic-link
endpoint, updates to the email sending logic, an improved email template, and comprehensive tests for both endpoints.Changes Introduced
1. Magic Link Request Endpoint (
POST /api/v1/auth/magic-link
)MagicLinkEmail
mailable.2. Magic Link Verification Endpoint (
POST /api/v1/auth/magic-link/verify
)email
andtoken
).is_active
to 1, updateslast_login_at
).3. Tests
send-magic-link
endpoint have been retained and improved.verify-magic-link
endpoint, covering:How Has This Been Tested?
Run the app locally using:
Use Postman to send a
POST
request to/api/v1/auth/magic-link
with the request body:Expected Responses:
For the verification endpoint, send a
POST
request to/api/v1/auth/magic-link/verify
with:Expected Successful Response (structure identical to login):
Run the tests with:
php artisan test --filter=MagicLinkTest
All tests should pass.
Documentation
Checklist
magic_link_token
andmagic_link_expires_at
is handled separately viaphp artisan migrate
.This PR now fully implements the magic link authentication flow—from requesting a magic link to verifying it and logging the user in—all while maintaining consistency with our existing login responses. Please review and let me know if any further changes are needed.