emile 1 year ago
parent 0399c7b18b
commit 9192d285ea

@ -37,19 +37,13 @@ def authenticate_customer(request):
try: try:
user = User.objects.get(email=email) user = User.objects.get(email=email)
except User.DoesNotExist: user = authenticate(request, user=user)
return JsonResponse({'success': False, 'error': 'User with this email does not exist'})
# Since you're not checking the password, you can simply authenticate the user object
user = authenticate(request, user=user)
if user is not None:
# Login the user
login(request, user) login(request, user)
return JsonResponse({'success': True, 'user': { return JsonResponse({'success': True, 'user': {
'id': user.id, 'id': user.id,
'email': user.email, 'email': user.email,
'username': user.username 'username': user.username
}}) }})
else: except User.DoesNotExist:
return JsonResponse({'success': False, 'error': 'Authentication failed'}) return JsonResponse({'success': False, 'error': 'User with this email does not exist'})

Loading…
Cancel
Save