Ho folks, i’m trying to implement a custom serializer in my Djoser auth to check for duplicate email on sign up. I was going to filter by email and if exists() I can raise a validation error, but can’t even get to that stage as my API call from the frontend always uses the default Djoser serializer. I’m out of ideas on how to solve this or debug what exactly is going on.
I’ve followed Djoser docs to implement custom validation.
Settings.
DJOSER = {
'USER_CREATE_PASSWORD_RETYPE': True,
'SERIALIZERS': {
'user_create': 'core.serializers.CustomUserCreateSerializer',
'user': 'core.serializers.CustomUserSerializer',
},
'PERMISSIONS' : {
'user_create': ['rest_framework.permissions.AllowAny']
}
}
Serliazers
class CustomUserCreateSerializer(UserCreateSerializer):
class Meta(UserCreateSerializer.Meta):
model = User
fields = ('id', 'email', 'username', 'password')
class CustomUserSerializer(UserSerializer):
class Meta(UserSerializer.Meta):
model = User
fields = ('id', 'email', 'username')
API call from React
async register(userData) {
try{
const response = await axiosInstance.post('/auth/users/', userData)
return response.data
} catch(error){
throw error.response.data
}
}
I’ve checked all imports are correct. Checked my project structure, all the simple things, to me it should be implemented.
Any input much appreciated.