web/django

GraduArt backend 구현 중에 겪은 문제 및 trouble shooting

민사민서 2024. 11. 6. 02:21
반응형

디자인이 이쁘네요

1. 장고 custom jwt authentication + custom user

2. allowany vs. isauthenticated decorator

3. 구글 로그인 using jwt token

https://minseosavestheworld.tistory.com/319

 

[django] custom authentication 및 custom user를 통해 구글 로그인 구현하기 (feat. supabase) - 1

코드 작성한지 몇 달 지나서 (사소한 트러블슈팅들은) 기억은 안나지만 세팅 방법 등을 정리해두고자 글을 남긴다~~  장고에서는 기본적으로 (여러 field와 method가 정의된) Users 모델을 제공하고

minseosavestheworld.tistory.com

https://minseosavestheworld.tistory.com/320

 

[django] custom authentication 및 custom user를 통해 구글 로그인 구현하기 (feat. supabase) - 2

이제 supabase의 sso 관련 api를 활용해 로그인 기능을 어떻게 구현했는지에 대해 알아보자. (오래되어서 자세한 디테일은 기억이 안나지만...) supabase에서 제공하는 api (https://supabase.com/docs/guides/auth/

minseosavestheworld.tistory.com

 

----- 여기부터는 직접 프론트 데모 만들어서 테스팅하며 마주친 trouble shooting ----

 

4. 프론트와 연결 시 oauth 로그인에서 애맥었던 점

백엔드로 리다이렉트 바로하면 hash(#) 이후의 token 가져올 방법 없음

구글 로그인 처리 - 구글 인증 확인 그 사이에 잠깐 머물 프론트 dummy page를 만들어야겠더라

 

6. broken pipe error 및 토큰 저장 안 됨

broken pipe error => AuthContext 초기화 과정과 구글 로그인 콜백 처리 간 동시실행

 

문제 시나리오:

구글 로그인 버튼 클릭 → 구글 인증 페이지로 리다이렉트
구글 인증 완료 → 콜백 URL로 리다이렉트
AuthContext 마운트 → /auth/user/ API 호출 (이때 아직 토큰이 없음)
토큰 없음 → 401 에러 → 토큰 리프레시 시도
리프레시 토큰도 없음 → 400 에러
동시에 GoogleCallback 컴포넌트에서 토큰 설정 시도
이 과정에서 connection이 끊어지면서 Broken pipe 에러 발생

 

=> 구글 콜백 처리 중에는 초기 인증 체크를 건너뛰도록 하자

 

7. Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.

어이없는 에러

https://velog.io/@black-pepper/Invalid-options-object.-Dev-Server-has-been-initialized-using-an-options-object-that-does-not-match-the-API-schema

 

----- 배포 시 trouble shooting -----

8. fly.io 에서 persistent volume 세팅 안해줘서 token blacklist 테이블 찾지 못함 => 로그아웃 기능 오류

 

아래와 같이 persistent volume 만들어주고, launch된 app에 연결

fly volumes create data_volume --size 1 --region nrt --app <app-name>

 

fly.toml 설정도 수정해줌

[mounts]
  source="data_volume"
  destination="/data"

 

settings.py도 수정해줌

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        'NAME': '/data/db.sqlite3', # for fly.io deploy
    }
}

 

이러면 별도의 postgresql 세팅 없이도 persistent volume 안에 token blacklist 테이블을 만들어 관리하기 시작

 

(만약 안된다면 fly machines remove <machineid> 로 machine 삭제, rm -rf ~/.fly로 캐시 삭제 후 다시 fly deploy ㄱㄱ)

(fly ssh console 로 ssh 접속 후 python manage.py migrate 해주어도 됨)

반응형