Skip to content

Conversation

@MaxCode2023
Copy link
Owner

No description provided.

Comment on lines +65 to +75
oauth2Service.fetchOAuthToken(code) { [weak self] result in
guard let self = self else { return }
switch result {
case .success:
self.switchToTabBarController()
case .failure:
print("failure fetchOAuthToken")
break
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Обычно именно ближе к UI части делают перевод на главную очередь, здесь это сделать удобнее, так как по сути только отобразить результат остается. Так ты избавишься от елочки в сервисе отправки запроса

private func switchToTabBarController() {
guard let window = UIApplication.shared.windows.first else { fatalError("Invalid Configuration") }
let tabBarController = UIStoryboard(name: "Main", bundle: .main)
.instantiateViewController(withIdentifier: "TabBarViewController")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

хорошо бы делать консистентно: если где-то индификатор используется как константа, то и здесь можно также

Comment on lines +75 to +77
// @IBAction func clickExitButton(_ sender: Any) {
//
// }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

убрать, либо вернуть заглушку (@objc с таргетом на кнопку)

import UIKit

final class SplashViewController: UIViewController {
private let ShowAuthenticationScreenSegueIdentifier = "ShowAuthenticationScreen"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется в прошлый раз уже говорила, что константы нужно именовывать в camelCase (ну либо единообразно по всему проекту)

Comment on lines +33 to +38
let path = "/oauth/token"
+ "?client_id=\(AccessKey)"
+ "&&client_secret=\(SecretKey)"
+ "&&redirect_uri=\(RedirectURI)"
+ "&&code=\(code)"
+ "&&grant_type=authorization_code"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь хорошо бы переписать на urlcomponents, потребуются path и queryItems

Comment on lines +15 to +22
return UserDefaults.standard.string(forKey: tokenKey)
}

set(newValue) {
if let token = newValue {
UserDefaults.standard.set(token, forKey: tokenKey)
} else {
UserDefaults.standard.removeObject(forKey: tokenKey)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserDefaults.standard - повторяется три раза, можно завести приватную константу


import Foundation

fileprivate let tokenKey = "BearerToken"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

обычно стараются избегать глобальных констант. Перенеси ее в класс либо сделай обертку

enum TokenStorageKeys {
case tokenKey = "BearerToken"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants