11async function getUserData ( ) {
2- const token = localStorage . getItem ( 'access_token' ) ;
3-
4- if ( ! token ) {
5- console . warn ( "로그인 토큰이 없습니다." ) ;
6- window . location . href = "/api/users/login/"
7- return null ;
8- }
9-
10- try {
11- const response = await fetch ( '/api/users/api/profile/' , {
12- method : 'GET' ,
13- headers : {
14- 'Authorization' : `Bearer ${ token } ` ,
15- 'Content-Type' : 'application/json'
16- }
17- } ) ;
18-
19- if ( response . ok ) {
20- const userData = await response . json ( ) ;
21- console . log ( "유저 정보 로드 성공:" , userData ) ;
22- return userData ;
23- } else {
24- console . error ( "토큰이 만료되었거나 유효하지 않습니다." ) ;
25- return null ;
26- }
27- } catch ( error ) {
28- alert ( "네트워크 오류 발생:" ) ;
29- window . location , href = "/api/users/login/"
30- return null ;
31- }
2+ const userData = await Auth . getData ( '/api/users/api/profile/' ) ;
3+ if ( userData ) console . log ( "유저 정보 로드 성공:" , userData ) ;
4+ return userData ;
325}
336
347async function renderProfile ( ) {
@@ -46,8 +19,6 @@ async function renderProfile() {
4619 const score_bar_fill = document . getElementById ( 'score_bar_fill' ) ;
4720 const imgEl = document . getElementById ( 'userprofile' ) ;
4821
49- score_bar_fill . style = `width : ${ user . manner_score } %;`
50-
5122 // 1. 기본 정보 반영
5223 if ( usernameElement ) usernameElement . innerText = user . username ;
5324 if ( univElement ) univElement . innerText = user . university ;
@@ -102,7 +73,7 @@ async function renderProfile() {
10273 mannerScore . innerText = `${ user . manner_score } 점` ;
10374 const scoreBar = document . querySelector ( '.score-bar-fill' ) ;
10475 if ( scoreBar ) {
105- scoreBar . style . width = `${ user . manner_score } %` ;
76+ scoreBar . style . width = `${ Math . round ( ( user . manner_score / 5 ) * 100 ) } %` ;
10677 }
10778 }
10879 }
@@ -118,40 +89,18 @@ function toggleReviews() {
11889}
11990
12091function logout ( ) {
121- localStorage . removeItem ( 'access_token' ) ;
122- localStorage . removeItem ( 'refresh_token' ) ;
12392 alert ( "로그아웃 되었습니다." ) ;
124- window . location . href = "/api/users/login/" ;
93+ Auth . logout ( "/api/users/login/" ) ;
12594}
12695
12796
12897async function signout ( ) {
129- const token = localStorage . getItem ( 'access_token' ) ;
130- if ( ! token ) return ;
131-
132- try {
133- const res = await fetch ( '/api/users/api/signout/' , {
134- method : 'DELETE' ,
135- headers : {
136- 'Authorization' : `Bearer ${ token } ` ,
137- 'Content-Type' : 'application/json'
138- }
139- } ) ;
140-
141- if ( res . ok ) {
142- const data = await res . json ( ) ;
143- localStorage . removeItem ( 'access_token' ) ;
144- localStorage . removeItem ( 'refresh_token' ) ;
145- console . error ( "회원 탈퇴 완료" ) ;
146- window . location . href = "/api/users/login/"
147- return
148- } else {
149- console . error ( "탈퇴 중 에러발생" ) ;
150- alert ( '에러' )
151- return null ;
152- }
153- } catch ( error ) {
154- console . error ( "오류 발생:" , error ) ;
98+ const res = await Auth . deleteData ( '/api/users/api/signout/' ) ;
99+ if ( res !== null ) {
100+ Auth . clearTokens ( ) ;
101+ window . location . href = "/api/users/login/" ;
102+ } else {
103+ alert ( '에러' ) ;
155104 }
156105}
157106
0 commit comments