Skip to content

Commit

Permalink
Error handling in the login page
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenshiv committed Dec 3, 2023
1 parent edcedc4 commit 423d6c7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
Binary file modified backend/artistsmgmt/__pycache__/views.cpython-310.pyc
Binary file not shown.
13 changes: 10 additions & 3 deletions backend/artistsmgmt/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,19 @@ def post(self, request, format=None):
# return self.request.user


class ArtistOnlyView(APIView):
# class ArtistOnlyView(APIView):
# permission_classes = [IsAuthenticated, IsArtist]
# serializer_class = UserSerializer

# def get(self, request, format=None):
# return Response(data={"message": "You are an artist"}, status=status.HTTP_200_OK)

class ArtistOnlyView(generics.RetrieveAPIView):
permission_classes = [IsAuthenticated, IsArtist]
serializer_class = UserSerializer

def get(self, request, format=None):
return Response(data={"message": "You are an artist"}, status=status.HTTP_200_OK)
def get_object(self):
return self.request.user


class ArtistCreateView(generics.ListCreateAPIView):
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ const HomePage = () => {
<div>
{userData ? (
<div>
<h1>{userData.message}!</h1>
{/* Display user-specific content */}
<h1>Welcome, {userData.username}!</h1>
</div>
) : (
<p>Loading...</p>
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/pages/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ const SignUpForm = () => {
}
} catch (error) {
console.error("Error during signup:", error);
setErrorMessage("Error during signup. Please try again.");
setSuccessMessage("");
if (error.response && error.response.status === 400) {
setErrorMessage("A user with that username already exists.");
} else {
setErrorMessage("Signup failed. Please try again.");
}
}
};

Expand Down

0 comments on commit 423d6c7

Please sign in to comment.