ChappieSignIn is the primary way to let users authenticate with their ChatGPT account. Drop it into any SwiftUI view alongside your ChappieAuthSession and the button handles the entire device-code flow — requesting the code, copying it to the clipboard, opening the verification URL, and polling for approval — all with an optional onboarding sheet that walks the user through each step.
Basic usage
Attach yourauthSession and apply any standard SwiftUI button modifiers:
Onboarding sheet
By defaultChappieSignIn presents a built-in sheet that guides users through three steps:
- Open OpenAI — a button that launches the verification URL in Safari
- Continue with ChatGPT — a reminder to tap Continue when prompted
- Paste your device code — the device code displayed in a tap-to-copy chip
Handling the device code yourself
If you want to integrate the device code into your own UI — for example, to display it inline or deep-link into a custom web view — disable the onboarding sheet and receive the code in theonDeviceCode closure:
showsOnboardingSheet is false. You can use onDeviceCode to update your own UI state at the same time.
Controlling notification permission
ChappieSignIn asks for notification permission the first time the button is tapped. You can suppress this if your app manages notification permission elsewhere:
Custom label
Provide alabel closure to replace the default ChappieSignInLabel with any SwiftUI view. The closure receives the button’s current title string so you can incorporate it into your own layout:
"Sign in with ChatGPT" → "Preparing sign in" → "Open ChatGPT sign in".
Legacy wrapper: SignInWithChatGPTButton
SignInWithChatGPTButton is a pre-styled wrapper around ChappieSignIn that fills the available width and applies a bold font. It is still available for compatibility, but new code should use ChappieSignIn directly for full control over layout and customisation.
Manual device-code flow
For advanced scenarios — custom authentication screens, command-line tooling, or integration tests — you can start the device-code flow directly without using any button:startDeviceCodeSignIn() returns as soon as the device code is ready. Background polling starts immediately — you don’t need to call anything else. Observe authSession.state or authSession.deviceLinkState to detect when the user approves the code.
ChappieDeviceLinkState values
deviceLinkState gives you finer-grained progress than state. Use it when you want to show a progress indicator that distinguishes between requesting the code, waiting for user action, and active polling.