emile 1 year ago
parent 0399c7b18b
commit 9192d285ea

@ -37,19 +37,13 @@ def authenticate_customer(request):
try:
user = User.objects.get(email=email)
except User.DoesNotExist:
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
user = authenticate(request, user=user)
login(request, user)
return JsonResponse({'success': True, 'user': {
'id': user.id,
'email': user.email,
'username': user.username
}})
else:
return JsonResponse({'success': False, 'error': 'Authentication failed'})
except User.DoesNotExist:
return JsonResponse({'success': False, 'error': 'User with this email does not exist'})

Loading…
Cancel
Save