try to login with a new registered fresh user. web login not completed sometimes randomly. Instagram shows a different user suggestion page. I try to follow 1 user, also 1 user followed me (it shows feed but not worked) mostly web login was not completed for this user. After trying 2-3 times to login it may work.
When you say newly registered, do you mean it happens when signing up from the web view, or when logging into an account that was just created but somewhere else? @canaksoy
Just to understand how to try and replicate it 😊
Either way, checking directly for cookies, instead of any given url, might be a fix (assuming they're all set before reaching the aforementioned suggestion page). I'm sending a pull request ASAP.
Check #76, @canaksoy 💪
Main change, other than not actually checking for instagram.com
but just for valid cookies, I've made the all init
process async
, in order not to break multi account support (I plan on dealing with this properly in 2.0
, either returning a UIViewController
or something like a LoginManager
creating the web view).
I'm waiting on @TheM4hd1's approval to actually merge it 😊
Turns out the LoginWebView
still worked even in the case described by @canaksoy above (I've both tested it myself and checked his screenshots), so I'm removing the bug
label for a help wanted
one.
Still, the PR is beneficial for future proofing the entire thing, and it should be merged imho.
For future reference… the new behaviour is this.
(@mkeshnoda)
class LoginViewController: UIViewController {
var webView: InstagramLoginWebView? {
didSet {
oldValue?.removeFromSuperview()
guard let webView = webView else { return }
// add to view hierarchy (NECESSARY).
view.addSubview(webView)
// always request log in page when setting a new web view.
webView.loadInstagramLogin()
}
}
override func viewDidLoad() {
super.viewDidLoad()
// create a new `InstagramLoginWebView`.
InstagramLoginWebView.create(with: view.bounds,
completionHandler: { _, _ in /* deal with login and failures */ },
returnHandler: { [weak self] in self?.webView = $0 })
}
}
For future reference… the new behaviour is this.
(@mkeshnoda)class LoginViewController: UIViewController { var webView: InstagramLoginWebView? { didSet { oldValue?.removeFromSuperview() guard let webView = webView else { return } // add to view hierarchy (NECESSARY). view.addSubview(webView) // always request log in page when setting a new web view. webView.loadInstagramLogin() } } override func viewDidLoad() { super.viewDidLoad() // create a new `InstagramLoginWebView`. InstagramLoginWebView.create(with: view.bounds, completionHandler: { _, _ in /* deal with login and failures */ }, returnHandler: { [weak self] in self?.webView = $0 }) } }
I did exactly the same but after logging-in didSuccessfullyLogIn and completionHandler is not working 😭
Just did a little debugging and found out that i can't login because of filtered.count = 1
. isUserLoggedIn(instagramCookies: [HTTPCookie]?)
recieves only 2 cookies
let filtered = cookies.filter {
!$0.value.isEmpty
&& $0.properties?[.init(rawValue: "Created")] as? TimeInterval ?? 0 > startedAt.timeIntervalSinceReferenceDate
&& ($0.name == "ds_user_id" || $0.name == "csrftoken" || $0.name == "sessionid") }
guard filtered.count >= 3 else { return }
Can you open a new issue with it and explain your flow? @mkeshnoda
Cause unfortunately those 3 cookies are very much needed, so there's nothing we can do to fix it… they literally mean "you are logged in".
And it's weird cause if it worked before, it should work just as well now (it already checked for at least 2 of them). I've tested with 4 different accounts and they all seem to work.