Skip to content

Commit cdfaf62

Browse files
fix: tighten GitHub app sign-in edge cases from review
- A 401 on a token or gh login no longer marks the app session refused; only the token GitHub rejected is refreshed. - A refresh only saves over the session it started from, so a sign-out or new sign-in during the request is not undone. - Cancel ends the server's sign-in attempt (sourceControl.signInCancel), so approving the code afterwards signs nothing in. - Installations are paged in full, and a repository list past the page cap counts its account as reached instead of nagging. - Repositories named as URLs or host/owner/name match coverage. - Mobile no longer alerts for a sign-in it cancelled or replaced. - Publishing a new repository suggests installing the app, as cloning does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3016993 commit cdfaf62

18 files changed

Lines changed: 235 additions & 46 deletions

File tree

‎apps/mobile/src/features/projects/AddProjectScreen.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,10 @@ export function AddProjectNewScreen(props: { readonly environmentId?: string | s
10001000
);
10011001
const environment = resolveAddProjectEnvironment(environmentOptions, selectedEnvironmentId);
10021002
const createNew = useAtomCommand(projectEnvironment.createNew, { reportFailure: false });
1003+
const checkPublishedAppAccess = useAtomCommand(sourceControlEnvironment.checkAppAccess, {
1004+
reportFailure: false,
1005+
reportDefect: false,
1006+
});
10031007
const publishRepository = useAtomCommand(sourceControlEnvironment.publishRepository, {
10041008
reportFailure: false,
10051009
});
@@ -1098,6 +1102,12 @@ export function AddProjectNewScreen(props: { readonly environmentId?: string | s
10981102
`Could not create the ${publishTarget.definition.label} repository`,
10991103
errorMessage(Cause.squash(publishResult.cause)),
11001104
);
1105+
} else {
1106+
void suggestAppAccessForRemote(
1107+
checkPublishedAppAccess,
1108+
environment.environmentId,
1109+
publishResult.value.remoteUrl,
1110+
);
11011111
}
11021112
});
11031113
}

‎apps/mobile/src/features/settings/components/SourceControlSignInSection.tsx‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "@t3tools/client-runtime/source-control-clients";
88
import * as Cause from "effect/Cause";
99
import * as Clipboard from "expo-clipboard";
10-
import { useState } from "react";
10+
import { useRef, useState } from "react";
1111
import { Alert, Linking } from "react-native";
1212

1313
import { serverEnvironment } from "../../../state/server";
@@ -73,6 +73,10 @@ function AppSignInRow(props: {
7373
const signedIn = (signIns[host] ?? "").length > 0;
7474
const start = useAtomCommand(sourceControlEnvironment.startSignIn, { reportFailure: false });
7575
const wait = useAtomCommand(sourceControlEnvironment.waitForSignIn, { reportFailure: false });
76+
const cancel = useAtomCommand(sourceControlEnvironment.cancelSignIn, { reportFailure: false });
77+
// The attempt a pending `wait` belongs to; a cancel or a newer attempt makes its outcome stale.
78+
const attempt = useRef<SourceControlSignInPrompt | null>(null);
79+
const input = { provider: definition.kind, host };
7680
const updateSettings = useAtomCommand(serverEnvironment.updateSettings, {
7781
label: `sign out of ${appSignIn.appName}`,
7882
});
@@ -84,26 +88,36 @@ function AppSignInRow(props: {
8488
prompt.userCode,
8589
`Enter this code on GitHub, then approve ${appSignIn.appName}. It is copied. The server finishes signing in even if you leave the app.`,
8690
[
87-
{ text: "Cancel", style: "cancel", onPress: () => setPending(null) },
91+
{
92+
text: "Cancel",
93+
style: "cancel",
94+
onPress: () => {
95+
attempt.current = null;
96+
setPending(null);
97+
void cancel({ environmentId, input });
98+
},
99+
},
88100
{ text: "Open GitHub", onPress: () => openUrl(prompt.verificationUri) },
89101
],
90102
);
91103
};
92104

93105
const signIn = async () => {
94106
setPending("starting");
95-
const input = { provider: definition.kind, host };
96107
const started = await start({ environmentId, input });
97108
if (started._tag !== "Success") {
98109
setPending(null);
99110
Alert.alert("Could not start the sign-in", failureMessage(started.cause));
100111
return;
101112
}
102113
const prompt = started.value;
114+
attempt.current = prompt;
103115
setPending(prompt);
104116
showCode(prompt);
105117
const finished = await wait({ environmentId, input });
106-
setPending((current) => (current === prompt ? null : current));
118+
if (attempt.current !== prompt) return;
119+
attempt.current = null;
120+
setPending(null);
107121
if (finished._tag !== "Success") {
108122
Alert.alert("Sign-in did not finish", failureMessage(finished.cause));
109123
}

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ const RPC_AGGREGATES = {
142142
[WS_METHODS.sourceControlPublishRepository]: "source-control",
143143
[WS_METHODS.sourceControlSignInStart]: "source-control",
144144
[WS_METHODS.sourceControlSignInWait]: "source-control",
145+
[WS_METHODS.sourceControlSignInCancel]: "source-control",
145146
[WS_METHODS.sourceControlAppAccess]: "source-control",
146147
[WS_METHODS.projectCloneStart]: "source-control",
147148
[WS_METHODS.projectCloneCancel]: "source-control",

‎apps/server/src/sourceControl/SourceControlSignIn.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export class SourceControlSignIn extends Context.Service<
2222
readonly wait: (
2323
input: SourceControlSignInInput,
2424
) => Effect.Effect<SourceControlSignInResult, SourceControlSignInError>;
25+
readonly cancel: (
26+
input: SourceControlSignInInput,
27+
) => Effect.Effect<void, SourceControlSignInError>;
2528
readonly access: (input: SourceControlAppAccessInput) => Effect.Effect<SourceControlAppAccess>;
2629
}
2730
>()("t3/sourceControl/SourceControlSignIn") {}
@@ -50,6 +53,9 @@ const make = Effect.gen(function* () {
5053
wait: Effect.fn("SourceControlSignIn.wait")(function* (input) {
5154
return yield* (yield* signInFor(input)).wait(input.host);
5255
}),
56+
cancel: Effect.fn("SourceControlSignIn.cancel")(function* (input) {
57+
return yield* (yield* signInFor(input)).cancel(input.host);
58+
}),
5359
access: Effect.fn("SourceControlSignIn.access")(function* (input) {
5460
const signIn = drivers.find(({ driver }) => driver.kind === input.provider)?.instance.signIn;
5561
return {

‎apps/server/src/ws.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,6 +2724,7 @@ export const layerWsRpc = (
27242724
sourceControlRepositories.cloneRepository(input),
27252725
[WS_METHODS.sourceControlSignInStart]: (input) => sourceControlSignIn.start(input),
27262726
[WS_METHODS.sourceControlSignInWait]: (input) => sourceControlSignIn.wait(input),
2727+
[WS_METHODS.sourceControlSignInCancel]: (input) => sourceControlSignIn.cancel(input),
27272728
[WS_METHODS.sourceControlAppAccess]: (input) => sourceControlSignIn.access(input),
27282729
[WS_METHODS.projectCloneStart]: (input) =>
27292730
projectCloneTracker.start(input, {

‎apps/web/src/components/settings/SourceControlAppSignInSettings.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export function SourceControlAppSignInSettings({
106106
);
107107
const start = useAtomCommand(sourceControlEnvironment.startSignIn, { reportFailure: false });
108108
const wait = useAtomCommand(sourceControlEnvironment.waitForSignIn, { reportFailure: false });
109+
const cancel = useAtomCommand(sourceControlEnvironment.cancelSignIn, { reportFailure: false });
109110
const updateSettings = useAtomCommand(serverEnvironment.updateSettings, {
110111
label: `sign out of ${appSignIn.appName}`,
111112
});
@@ -179,7 +180,14 @@ export function SourceControlAppSignInSettings({
179180
} else if (waiting !== null) {
180181
subtitle = "Approve the app on GitHub to finish signing in.";
181182
action = (
182-
<Button size="xs" variant="ghost" onClick={() => setState({ status: "idle" })}>
183+
<Button
184+
size="xs"
185+
variant="ghost"
186+
onClick={() => {
187+
setState({ status: "idle" });
188+
void cancel({ environmentId, input: { provider: definition.kind, host } });
189+
}}
190+
>
183191
Cancel
184192
</Button>
185193
);

‎apps/web/src/hooks/useNewProject.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { projectEnvironment } from "~/state/projects";
1515
import { sourceControlEnvironment } from "~/state/sourceControl";
1616
import { useAtomCommand } from "~/state/use-atom-command";
1717
import { useNewThreadHandler } from "./useHandleNewThread";
18+
import { suggestAppAccessForRemote } from "../components/sourceControlAppAccessToast";
1819

1920
function errorMessage(error: unknown): string {
2021
return error instanceof Error && error.message.trim().length > 0
@@ -63,6 +64,7 @@ export function useNewProject() {
6364
description: result.value.repository.nameWithOwner,
6465
}),
6566
);
67+
void suggestAppAccessForRemote(input.environmentId, result.value.remoteUrl);
6668
};
6769

6870
return async (input: {

‎apps/web/src/state/sourceControlActions.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ vi.mock("@effect/atom-react", () => ({
1919
useAtomValue: () => ({ operation: null, error: null, isRunning: false }),
2020
}));
2121
vi.mock("../rpc/atomRegistry", () => ({ appAtomRegistry: {} }));
22+
vi.mock("../components/sourceControlAppAccessToast", () => ({
23+
suggestAppAccessForRemote: () => Promise.resolve(),
24+
}));
2225
vi.mock("./session", () => ({
2326
useEnvironmentScope: (environmentId: string, scope: string) =>
2427
state.scopes.get(environmentId)?.has(scope) === true,

‎apps/web/src/state/sourceControlActions.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { readEnvironmentScope, useEnvironmentScope } from "./session";
3131
import { sourceControlEnvironment } from "./sourceControl";
3232
import { useAtomCommand } from "./use-atom-command";
3333
import { vcsActionManager, vcsEnvironment } from "./vcs";
34+
import { suggestAppAccessForRemote } from "../components/sourceControlAppAccessToast";
3435

3536
export type SourceControlActionKind =
3637
| "init"
@@ -286,13 +287,17 @@ export function useSourceControlPublishRepositoryAction(scope: SourceControlActi
286287
),
287288
);
288289
}
289-
return publishRepository({
290+
const result = await publishRepository({
290291
environmentId: target.environmentId,
291292
input: {
292293
cwd: target.cwd,
293294
...input,
294295
},
295296
});
297+
if (result._tag === "Success") {
298+
void suggestAppAccessForRemote(target.environmentId, result.value.remoteUrl);
299+
}
300+
return result;
296301
};
297302
return useAction({
298303
kind: "publishRepository",

‎packages/client-runtime/src/state/sourceControl.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ export function createSourceControlEnvironmentAtoms<R, E>(
8383
label: "environment-data:source-control:sign-in-wait",
8484
tag: WS_METHODS.sourceControlSignInWait,
8585
}),
86+
cancelSignIn: createEnvironmentRpcCommand(runtime, {
87+
label: "environment-data:source-control:sign-in-cancel",
88+
tag: WS_METHODS.sourceControlSignInCancel,
89+
}),
8690
projectClones: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
8791
label: "environment-data:source-control:project-clones",
8892
tag: WS_METHODS.subscribeProjectClones,

0 commit comments

Comments
 (0)