Skip to content

Commit e8ccffd

Browse files
authored
Merge pull request #136 from eurosky-social/fix/onboarding
fix: show onboarding after OAuth signup without a reload
2 parents 317ac81 + 5b648cd commit e8ccffd

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

src/App.web.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ import {Provider as ShellStateProvider} from '#/state/shell'
4545
import {Provider as ComposerProvider} from '#/state/shell/composer'
4646
import {Provider as LandingProvider} from '#/state/shell/landing'
4747
import {Provider as LoggedOutViewProvider} from '#/state/shell/logged-out'
48-
import {Provider as OnboardingProvider} from '#/state/shell/onboarding'
48+
import {
49+
Provider as OnboardingProvider,
50+
useOnboardingDispatch,
51+
} from '#/state/shell/onboarding'
4952
import {Provider as ProgressGuideProvider} from '#/state/shell/progress-guide'
5053
import {Provider as SelectedFeedProvider} from '#/state/shell/selected-feed'
5154
import {Provider as HiddenRepliesProvider} from '#/state/threadgate-hidden-replies'
@@ -97,6 +100,7 @@ function InnerApp() {
97100
const [isReady, setIsReady] = useState(false)
98101
const {currentAccount} = useSession()
99102
const {resumeSession, login} = useSessionApi()
103+
const onboardingDispatch = useOnboardingDispatch()
100104
const theme = useColorModeTheme()
101105
const themesOverride = useThemesOverride() // Eurosky: per-user accent
102106
const {t: l} = useLingui()
@@ -108,7 +112,11 @@ function InnerApp() {
108112
try {
109113
// Finish an OAuth sign-in if we returned to the site root with
110114
// callback params; otherwise resume the stored session as usual.
111-
if (await tryFinishWebOAuthSignIn(login)) {
115+
if (
116+
await tryFinishWebOAuthSignIn(login, () =>
117+
onboardingDispatch({type: 'start'}),
118+
)
119+
) {
112120
return
113121
}
114122
if (account) {
@@ -124,7 +132,7 @@ function InnerApp() {
124132
}
125133
const account = readLastActiveAccount()
126134
void onLaunch(account)
127-
}, [resumeSession, login])
135+
}, [resumeSession, login, onboardingDispatch])
128136

129137
useEffect(() => {
130138
return listenSessionDropped(() => {

src/state/session/oauth-web-callback.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* provider returns the user to `/` with params, and we finish sign-in at
77
* app startup here.
88
*/
9-
import * as persisted from '#/state/persisted'
109
import {type SessionApiContext} from '#/state/session/types'
1110
import {
1211
getWebOAuthClient,
@@ -46,17 +45,12 @@ function hasOAuthCallbackParams(): boolean {
4645
*/
4746
export async function tryFinishWebOAuthSignIn(
4847
login: SessionApiContext['login'],
48+
startOnboarding: () => void,
4949
): Promise<boolean> {
5050
if (!hasOAuthCallbackParams()) return false
5151
const client = getWebOAuthClient()
5252
const result = await client.init()
5353
if (result?.session) {
54-
// A fresh signup (prompt=create) is created on the external PDS page, which
55-
// never runs our in-app signup wizard - so start onboarding here, the same
56-
// way that wizard does. Plain sign-ins carry no state and are untouched.
57-
if (result.state === OAUTH_SIGNUP_STATE) {
58-
await persisted.write('onboarding', {step: 'Welcome'})
59-
}
6054
// For a handle step-up the DID is unchanged, so login() replaces the
6155
// existing session in place with the upgraded (identity:handle) tokens.
6256
await login(
@@ -68,6 +62,20 @@ export async function tryFinishWebOAuthSignIn(
6862
},
6963
'LoginForm',
7064
)
65+
// A fresh signup (prompt=create) is created on the external PDS page, which
66+
// never runs our in-app signup wizard - so start onboarding here, the same
67+
// way that wizard does. Plain sign-ins carry no state and are untouched.
68+
//
69+
// We drive the in-memory onboarding reducer (startOnboarding) rather than
70+
// only writing persisted state. OnboardingProvider is mounted above the
71+
// session, so login() never remounts it, and on web persisted.write() does
72+
// not fire onUpdate listeners in the same tab (its cross-tab
73+
// BroadcastChannel never echoes back to the sender). A bare write would
74+
// leave the onboarding context stale and the wizard would not appear until
75+
// a manual reload. The reducer's 'start' action persists the step itself.
76+
if (result.state === OAUTH_SIGNUP_STATE) {
77+
startOnboarding()
78+
}
7179
if (result.state === OAUTH_HANDLE_STEPUP_STATE) {
7280
// The redirect lands at the site root; rewrite the path before the
7381
// navigator reads it so web linking resolves to account settings, where

0 commit comments

Comments
 (0)