Skip to content

Commit

Permalink
Fix: localhost:5173 에서 안되는거 테스트3
Browse files Browse the repository at this point in the history
  • Loading branch information
newbission committed Jun 19, 2024
1 parent 5fcf214 commit 6ebf245
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
11 changes: 8 additions & 3 deletions app/users/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def get_cookie_domain(host):
return host.split(":")[0]


def get_cookie_settings(request, token):
def get_cookie_settings(request, token, dev):
host = get_user_host(request)
is_product = get_is_product(host)

Expand All @@ -121,8 +121,13 @@ def get_cookie_settings(request, token):
"secure": is_product
}

if dev:
print(get_cookie_domain(host))
cookie_settings["domain"] = None
print(is_product)

return cookie_settings


def set_jwt_cookie(request, response, token):
response.set_cookie(**get_cookie_settings(request, token))
def set_jwt_cookie(request, response, token, dev=None):
response.set_cookie(**get_cookie_settings(request, token, dev))
23 changes: 10 additions & 13 deletions app/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class LoginCallbackView(APIView):
authentication_classes = []

def get(self, request, social, dev):

data = request.query_params.copy()

code = data.get("code")
Expand All @@ -72,20 +72,17 @@ def get(self, request, social, dev):
user = slcs.get_user(social_token)
# 가져온 user 객체를 통해 access_token 생성
access_token = slcs.get_access_token(user)
return Response({
"host": get_user_host(request),
"remote": get_user_remote(request),
"domain": get_cookie_settings(request, access_token)
})
def get_response(host):
# return Response(get_cookie_settings(request, access_token, dev))
def get_response(host, dev=None):
if dev:
redirect_uri = ["https://ndd.life", "http://localhost:5173"]
return redirect(redirect_uri[dev])
if host.startswith("127.0.0.1"):
return Response(get_cookie_settings(request, access_token))
redirect_http = {"ndd.life": "https", "localhost": "http"}
remote = host.split(":")[0]
return redirect(f"{redirect_http[remote]}://{host}")
return Response(get_cookie_settings(request, access_token, dev))

response = get_response(get_user_host(request))
set_jwt_cookie(request, response, access_token)
response = get_response(get_user_host(request), dev)
set_jwt_cookie(request, response, access_token, dev)

user.last_login = timezone.now()
user.is_login = True
Expand Down

0 comments on commit 6ebf245

Please sign in to comment.