FEAT(auth): implement magic link authentication #642
Merged
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.