Skip to content

Commit

Permalink
๐Ÿ› :: [#66] Edit ISO 8601: "yyyy-MM-ddTHH:mm:ss" ์œผ๋กœ ํ˜•์‹ ๋ณ€๊ฒฝ
Browse files Browse the repository at this point in the history
  • Loading branch information
Xixn2 committed Nov 15, 2024
1 parent 992c6a8 commit dcf586d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct SigninView: View {

}
.navigationDestination(isPresented: $isActiveSignin) {
SignupView(viewModel: AuthViewModel())
TabBarView()
}
.padding(.top, 152)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,64 +93,38 @@ public final class AuthViewModel: ObservableObject {
case 200:
let signInResponse = try result.map(SigninResponse.self)

// ๋งŒ๋ฃŒ ์‹œ๊ฐ„์„ ํ˜„์žฌ๋กœ๋ถ€ํ„ฐ์˜ ์‹œ๊ฐ„ ๋Œ€์‹  `Date(timeIntervalSince1970:)`์œผ๋กœ ๋ณ€ํ™˜
if let accessTokenExpiresIn = Double(signInResponse.accessTokenExpiresIn),
let refreshTokenExpiresIn = Double(signInResponse.refreshTokenExpiresIn) {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)

let accessTokenExpirationDate = Date(timeIntervalSince1970: accessTokenExpiresIn)
let refreshTokenExpirationDate = Date(timeIntervalSince1970: refreshTokenExpiresIn)
if let accessTokenExpirationDate = dateFormatter.date(from: signInResponse.accessTokenExpiresIn),
let refreshTokenExpirationDate = dateFormatter.date(from: signInResponse.refreshTokenExpiresIn) {

let accessTokenExpirationInterval = accessTokenExpirationDate.timeIntervalSinceNow
let refreshTokenExpirationInterval = refreshTokenExpirationDate.timeIntervalSinceNow

KeyChain.shared.saveTokenWithExpiration(
key: Const.KeyChainKey.accessToken,
token: signInResponse.accessToken,
expiresIn: accessTokenExpirationDate.timeIntervalSinceNow
expiresIn: accessTokenExpirationInterval
)

KeyChain.shared.saveTokenWithExpiration(
key: Const.KeyChainKey.refreshToken,
token: signInResponse.refreshToken,
expiresIn: refreshTokenExpirationDate.timeIntervalSinceNow
expiresIn: refreshTokenExpirationInterval
)

// ๋งŒ๋ฃŒ ์‹œ๊ฐ„ ํ™•์ธ์„ ์œ„ํ•œ ์ถœ๋ ฅ
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
dateFormatter.timeZone = TimeZone.current

print("Access Token ๋งŒ๋ฃŒ ๋‚ ์งœ: \(dateFormatter.string(from: accessTokenExpirationDate))")
print("Refresh Token ๋งŒ๋ฃŒ ๋‚ ์งœ: \(dateFormatter.string(from: refreshTokenExpirationDate))")
print("Access Token ๋งŒ๋ฃŒ ๋‚ ์งœ: \(accessTokenExpirationDate)")
print("Refresh Token ๋งŒ๋ฃŒ ๋‚ ์งœ: \(refreshTokenExpirationDate)")
} else {
print("๋งŒ๋ฃŒ ์‹œ๊ฐ„ ๋ณ€ํ™˜ ์˜ค๋ฅ˜: accessTokenExpiresIn ๋˜๋Š” refreshTokenExpiresIn์ด Double๋กœ ๋ณ€ํ™˜๋˜์ง€ ์•Š์Œ.")
print("๋งŒ๋ฃŒ ์‹œ๊ฐ„ ๋ณ€ํ™˜ ์˜ค๋ฅ˜: ์œ ํšจํ•œ ๋‚ ์งœ ํ˜•์‹์ด ์•„๋‹˜.")
}

DispatchQueue.main.async {
completion(statusCode, signInResponse.accessToken, signInResponse.refreshToken)
}

case 400:
print("400ใ…ฃ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.")
DispatchQueue.main.async {
completion(statusCode, nil, nil)
}

case 403:
print("403ใ…ฃ์•„์ง ๋ณด๋ฅ˜์ค‘์ž…๋‹ˆ๋‹ค.")
DispatchQueue.main.async {
completion(statusCode, nil, nil)
}

case 404:
print("404ใ…ฃ๊ณ„์ •์„ ์ฐพ์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.")
DispatchQueue.main.async {
completion(statusCode, nil, nil)
}

case 500..<600:
print("\(statusCode)ใ…ฃ์„œ๋ฒ„์˜ค๋ฅ˜์ž…๋‹ˆ๋‹ค.")
DispatchQueue.main.async {
completion(statusCode, nil, nil)
}

default:
print("Unhandled status code: \(statusCode)")
DispatchQueue.main.async {
Expand All @@ -173,8 +147,6 @@ public final class AuthViewModel: ObservableObject {
}
}



// MARK: - Sign Up
func signUp(completion: @escaping (Bool) -> Void) {
let params = SignupRequest(name: name, nickname: nickname, email: email, password: password, phoneNumber: phoneNumber)
Expand Down

0 comments on commit dcf586d

Please sign in to comment.