Common issues and their solutions.
# Clear cache
php bin/console cache:clear
# Check bundle is registered
php bin/console debug:container BetterAuth
# If still not found, check config/bundles.php
Solution: Ensure the bundle is in config/bundles.php:
return [
// ...
BetterAuth\Symfony\BetterAuthBundle::class => ['all' => true],
];
# Dump autoloader
composer dump-autoload
# Clear Symfony cache
php bin/console cache:clear
# Reinstall dependencies
rm -rf vendor/
composer install
# Check schema
php bin/console doctrine:schema:validate
# Force migration
php bin/console doctrine:migrations:migrate --no-interaction
# Create migration manually
php bin/console doctrine:migrations:diff
Cause: Missing Authorization header.
Solution:
// Add header to requests
headers: {
'Authorization': `Bearer ${accessToken}`
}
Causes:
Solutions:
# Check secret matches
php bin/console debug:config better_auth secret
# Regenerate token
curl -X POST /auth/refresh -d '{"refreshToken": "xxx"}'
Cause: Access token lifetime exceeded.
Solution: Implement token refresh:
// Refresh token before expiration
const response = await fetch('/auth/refresh', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ refreshToken }),
});
Causes:
Debug:
// Check user exists
$user = $userRepository->findByEmail($email);
dump($user);
// Check password
$isValid = $passwordHasher->isPasswordValid($user, $password);
dump($isValid);
Causes:
withCredentialsSolutions:
# config/packages/nelmio_cors.yaml
nelmio_cors:
defaults:
allow_credentials: true
axios.defaults.withCredentials = true;
setCookie('token', $value, [
'samesite' => 'lax', // or 'none' for cross-site
'secure' => true, // HTTPS only in production
]);
Causes:
Solutions:
better_auth:
session:
lifetime: 604800 # 7 days
Cause: Mismatch between configured URI and provider settings.
Solution: Ensure exact match:
# config/packages/better_auth.yaml
better_auth:
oauth:
providers:
google:
redirect_uri: 'https://myapp.com/auth/oauth/google/callback'
Must match exactly in Google Console, including:
Causes:
Solution: Start OAuth flow again.
Debug:
# Check route exists
php bin/console debug:router | grep oauth
# Check logs
tail -f var/log/dev.log
Causes:
Solutions:
dateCauses:
Debug:
// Check QR code data
dump($totpData->getUri());
// Should be: otpauth://totp/Issuer:email?secret=XXX&issuer=Issuer
Solution: Use backup codes:
# Enter backup code instead of TOTP code
curl -X POST /auth/login/2fa -d '{"email":"...", "password":"...", "code":"12345678"}'
Causes:
Solutions:
# Use database indexes
# In your User entity
#[ORM\Index(columns: ['email'])]
Cause: Argon2id memory cost too high.
Solution:
# config/packages/security.yaml
security:
password_hashers:
App\Entity\User:
algorithm: argon2id
memory_cost: 32768 # Reduce from default 65536
# Run migrations
php bin/console doctrine:migrations:migrate
# Or create schema directly
php bin/console doctrine:schema:update --force
Cause: Entity changed but migration not run.
# Generate migration
php bin/console doctrine:migrations:diff
# Run it
php bin/console doctrine:migrations:migrate
Cause: Cascade delete not configured.
Solution:
#[ORM\OneToMany(targetEntity: Session::class, mappedBy: 'user', cascade: ['remove'])]
private Collection $sessions;
# Check config syntax
php bin/console lint:yaml config/packages/better_auth.yaml
# Debug config
php bin/console debug:config better_auth
# Check .env is loaded
php bin/console debug:dotenv
# Check specific variable
php bin/console debug:container --env-var=BETTER_AUTH_SECRET
# config/packages/dev/better_auth.yaml
better_auth:
debug: true
# Real-time logs
tail -f var/log/dev.log
# Filter auth logs
grep better_auth var/log/dev.log
# Specific errors
grep ERROR var/log/dev.log
// In controller
dump($request->headers->all());
dump($request->getContent());
dump($request->cookies->all());
# Decode Paseto token (for debugging only)
# Use a Paseto library or online decoder
| Error | Code | Solution |
|---|---|---|
| No token provided | 401 | Add Authorization header |
| Invalid token | 401 | Token corrupted, refresh |
| Token expired | 401 | Call /auth/refresh |
| Invalid credentials | 401 | Check email/password |
| User already exists | 400 | Email taken, use different |
| Invalid email format | 400 | Use valid email |
| Password too short | 400 | Min 8 characters |
| 2FA code invalid | 401 | Check code, wait for new |
| Rate limit exceeded | 429 | Wait and retry |
| State mismatch | 400 | Restart OAuth flow |
var/log/dev.logphp bin/console debug:config better_authHow can I help you explore Laravel packages today?