Skip to content

Commit bdd02ce

Browse files
committed
Fix missing survey
1 parent 41b7281 commit bdd02ce

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

web/oss/src/hooks/usePostAuthRedirect.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {userAtom} from "@/oss/state/profile/selectors/user"
1616
import {useProjectData} from "@/oss/state/project"
1717
import {authFlowAtom} from "@/oss/state/session"
1818
import {buildPostLoginPath, waitForWorkspaceContext} from "@/oss/state/url/postLoginRedirect"
19+
import {writePostSignupPending} from "@/oss/state/url/auth"
1920

2021
interface AuthUserLike {
2122
createdNewRecipeUser?: boolean
@@ -37,6 +38,7 @@ const usePostAuthRedirect = () => {
3738
const [invite] = useLocalStorage<Record<string, unknown>>("invite", {})
3839
const authUpgradeOrgKey = "authUpgradeOrgId"
3940
const lastSsoOrgSlugKey = "lastSsoOrgSlug"
41+
const postSignupPendingKey = "postSignupPending"
4042

4143
const hasInviteFromQuery = useMemo(() => {
4244
const token = router.query?.token
@@ -79,6 +81,7 @@ const usePostAuthRedirect = () => {
7981
await router.push("/workspaces/accept?survey=true")
8082
} else {
8183
console.log("[post-auth] redirect new user -> /post-signup")
84+
writePostSignupPending()
8285
await resetAuthState()
8386
await router.push("/post-signup")
8487
}

web/oss/src/state/url/auth.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export interface InvitePayload {
2727
}
2828

2929
const INVITE_STORAGE_KEY = "invite"
30+
const POST_SIGNUP_PENDING_KEY = "postSignupPending"
31+
const POST_SIGNUP_TTL_MS = 2 * 60 * 1000
3032
let authOrgFetchInFlight = false
3133

3234
export const protectedRouteReadyAtom = atom(false)
@@ -99,6 +101,41 @@ export const isCurrentAcceptRouteForInvite = (appState: any, invite: InvitePaylo
99101
return currentToken === invite.token
100102
}
101103

104+
export const writePostSignupPending = () => {
105+
if (!isBrowser) return
106+
try {
107+
window.sessionStorage.setItem(
108+
POST_SIGNUP_PENDING_KEY,
109+
JSON.stringify({ts: Date.now()}),
110+
)
111+
} catch {
112+
// ignore storage failures
113+
}
114+
}
115+
116+
const readPostSignupPending = (): boolean => {
117+
if (!isBrowser) return false
118+
try {
119+
const raw = window.sessionStorage.getItem(POST_SIGNUP_PENDING_KEY)
120+
if (!raw) return false
121+
const parsed = JSON.parse(raw) as {ts?: number}
122+
if (!parsed?.ts) return false
123+
if (Date.now() - parsed.ts > POST_SIGNUP_TTL_MS) return false
124+
return true
125+
} catch {
126+
return false
127+
}
128+
}
129+
130+
const clearPostSignupPending = () => {
131+
if (!isBrowser) return
132+
try {
133+
window.sessionStorage.removeItem(POST_SIGNUP_PENDING_KEY)
134+
} catch {
135+
// ignore storage failures
136+
}
137+
}
138+
102139
export const syncAuthStateFromUrl = (nextUrl?: string) => {
103140
if (!isBrowser) return
104141

@@ -148,11 +185,22 @@ export const syncAuthStateFromUrl = (nextUrl?: string) => {
148185
asPath,
149186
baseAppURL,
150187
})
188+
clearPostSignupPending()
151189
}
152190
if (isAuthCallbackRoute) {
153191
store.set(protectedRouteReadyAtom, false)
154192
return
155193
}
194+
if (isAuthRoute) {
195+
if (readPostSignupPending()) {
196+
clearPostSignupPending()
197+
void Router.replace("/post-signup").catch((error) => {
198+
console.error("Failed to redirect to post-signup:", error)
199+
})
200+
store.set(protectedRouteReadyAtom, false)
201+
return
202+
}
203+
}
156204
if (typeof window !== "undefined") {
157205
const upgradeOrgId = window.localStorage.getItem("authUpgradeOrgId")
158206
const identifiers = store.get(appIdentifiersAtom)

0 commit comments

Comments
 (0)