Back

.registerOAuthHandler View modifier can crash.

  • 0
  • Apple
Quasar
18 Jun, 2024, 20:48

I realize that this modifier was created to be attached to the view that would be present for a callback listener. But even in the event that this modifier was positioned elsewhere, it should fail silently rather than force unwrap cookies. There could be other deeplinks happening at the same time. Alternatively we should be able to apply this modifier to the root view or even listen to a specific route and roward it accordlingly. Nevertheless, we shouldn't be force unwrapping anything here.

TL;DR
.registerOAuthHandler View modifier can crash due to force unwrapping URLComponents without validation. The suggested solution is to add validation before proceeding. Additionally, it's mentioned that the modifier doesn't necessarily have to be attached to the same view as the callback listener.
Quasar
18 Jun, 2024, 20:50

Maybe i'm misunderstanding the logic in the modifier.

TypeScript
    public func registerOAuthHandler() -> some View {
        onOpenURL { url in
            WebAuthComponent.handleIncomingCookie(from: url)
        }.onReceive(NotificationCenter.default.publisher(for: notificationType)) { _ in
            WebAuthComponent.onCallback()
        }
    }

I was under the impression that this modifier was required. Are we suppose to be building our own?

Quasar
18 Jun, 2024, 20:56

i'd think we could modify this to validate the URLComponents before continuing..

TypeScript
    public static func handleIncomingCookie(from url: URL) {

        guard let components = URLComponents(string: url.absoluteString)!,
        validateQueryComponent(components) else {
            return 
        }
        let components = URLComponents(string: url.absoluteString)!
        
        let cookieParts = [String: String](uniqueKeysWithValues: components.queryItems!.map {
            ($0.name, $0.value!)
        })



        func validateQueryComponents(_ components: URLComponents) -> Bool {
            ....  to validate
        }
Quasar
18 Jun, 2024, 20:57

that way the app doesn't have to be open to recieve the url, and not crash any other deeplinks i care to listen for elsewhere in the app.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more