mydaniel/laravel-temporary-tokens
User) or exist independently, enabling modular integration without tight coupling to authentication systems.vendor:publish), so it works with any supported database (MySQL, PostgreSQL, SQLite).TokenGenerated, TokenValidated) for custom logic (e.g., logging, notifications).temporary_tokens). Scaling token volume (e.g., millions of OTPs) may require indexing or partitioning strategies.usage_count).temporary-tokens:prune could conflict with existing cron jobs or require manual scheduling.temporary-tokens:prune command (e.g., cron setup, error handling)?composer.json constraints).spatie/laravel-activitylog) for higher scalability.composer require mydaniel/laravel-temporary-tokens
php artisan vendor:publish --provider="MyDaniel\TemporaryTokens\TemporaryTokensServiceProvider"
php artisan migrate
config/temporary-tokens.php (e.g., default token length, TTL).app/Console/Kernel.php:
$schedule->command('temporary-tokens:prune')->daily();
use MyDaniel\TemporaryTokens\Facades\TemporaryToken;
$token = TemporaryToken::generate([
'length' => 6,
'expires_at' => now()->addMinutes(10),
'model' => $user, // Optional: Associate with Eloquent model
'metadata' => ['purpose' => 'password_reset'],
]);
if (TemporaryToken::validate($tokenValue, $user)) {
// Token is valid and unused.
}
usage_count > 0).| Phase | Tasks |
|---|---|
| Discovery | Audit existing token systems; define requirements (e.g., token types, TTL). |
| Proof of Concept | Implement a single use case (e.g., password reset OTPs) in staging. |
| Integration | Replace legacy token logic; update frontend/backend to use the package. |
| Optimization | Add Redis caching for high-volume tokens; monitor pruning performance. |
| Rollout | Deploy to production; monitor token validation success rates. |
TokenGenerated, TokenValidationFailed).token, expires_at, and model_id.temporary_tokens table by created_at.redis:tokens with TTL).temporary-tokens:prune across multiple workers if token volume is high.| Failure Scenario | Impact | Mitigation Strategy |
|---|---|---|
| Database downtime | Tokens unavailable | Use Redis as a fallback for critical tokens. |
| Pruning command failure | Stale tokens accumulate | Monitor cron job logs; add retries. |
| Token validation race condition | Duplicate usage | Use database transactions or Redis locks. |
| Token table corruption | Data loss | Regular DB backups; test restore procedures. |
| Package version incompatibility | Breaking changes | Pin package version in composer.json. |
temporary-tokens:prune --dry-run).How can I help you explore Laravel packages today?