회의 최소화
import json
import bcrypt
import jwt
import requests
from django.shortcuts import redirect
from django.views import View
from django.http import JsonResponse, HttpResponse
from django.core.exceptions import ObjectDoesNotExist
from django.db import IntegrityError
from my_settings import SECRET_KEY, KAKAO_KEY
from .models import User, Creator
class KakaoLoginView(View):
def get(self,request):
access_token = request.headers.get('Authorization')
# 헤더에 Authorization으로 오는게 맞는지?, 토큰의 키가 맞는지?
user_profile = requests.get(
'https://kapi.kakao.com//v2/user/me',
headers={'Authorization' : f'Bearer {access_token}'}
)
json_user_profile = user_profile.json()
print(json_user_profile)
nickname = json_user_profile['properties']['nickname']
print(nickname)
username = User.objects.create(
username = nickname
)
return JsonResponse({"message":nickname},status=200)
문제점 :
1. 토큰이 바뀌면 로직이 불안정하다-> 유닛테스트 아직 안 해봄
2. 현재 에러 난 상황
IntegrityError at /user/login
(1062, "Duplicate entry '' for key 'email'")
분명 이메일 중간에 한 번 밖에 확인 안 하고 다시 없앴는데 듀플리케이트 에러가 남. 아직 해결이 안 됨.
전반적으로 볼 때 소셜로그인 하는 법만 찾다가 겨우 방법 알아냈는데 그거마저 또 오류가 난 상황이라 크게 한 것이 없게 됨.