Skip to content

Commit

Permalink
#92 Feat: 토큰 정보로 유저 반환하는 API 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
fnzksxl committed Sep 19, 2024
1 parent e842ac4 commit 9d00467
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions wtnt/user/auth/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@


class AuthService(BaseService):
def get_user(self):
user_id = self.request.user.id
user = User.objects.get(pk=user_id)
serializer = UserSerializer(user)

return serializer.data

def determine_callback_url(self):
is_web = self.request.META.get("HTTP_X_FROM", None)
is_debug = self.request.META.get("HTTP_X_DEBUG", None)
Expand Down
2 changes: 2 additions & 0 deletions wtnt/user/auth/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
FinishGithubLoginView,
WtntTokenRefreshView,
EmailVerifyView,
GetUserDataByJWT,
)

urlpatterns = [
Expand All @@ -15,4 +16,5 @@
path("logout", LogoutView.as_view(), name="logout"),
path("token/refresh", WtntTokenRefreshView.as_view(), name="token-refresh"),
path("email", EmailVerifyView.as_view(), name="verify-email"),
path("get-user", GetUserDataByJWT.as_view(), name="get-user"),
]
8 changes: 8 additions & 0 deletions wtnt/user/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def post(self, request):
return Response({"user": data}, status=status.HTTP_201_CREATED)


class GetUserDataByJWT(APIView):
def get(self, request):
auth_service = AuthService(request)
data = auth_service.get_user()

return Response({"user": data}, status=status.HTTP_200_OK)


class WtntTokenRefreshView(TokenRefreshView):
def post(self, request: Request, *args, **kwargs):
refresh_service = RefreshService(request)
Expand Down

0 comments on commit 9d00467

Please sign in to comment.