A first local sign-in after an unknown Oficina arrival resumes the link
Astra's P2 on #23: connect resumes the link from /auth/local/complete, and that needs the person's users row. An admitted address signing in for the first time had none (currentUser makes it on the first page), so the resume fell to /account/home, which answered 403. homeLocalComplete now creates the row for a fresh, admitted local session first, as currentUser would, sample deck included, then hands on to connect. The regression test deletes the fixture's user and runs the whole flow; it failed with "303 /account/home" before this.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+57
−3
internal/slides/app.go+1 −1internal/slides/home.go+29 −0internal/slides/home_menu_test.go+27 −2
CI passed — run details
diff --git a/internal/slides/app.go b/internal/slides/app.go| index 6f08bc2..349aa82 100644 |
| --- a/internal/slides/app.go |
| +++ b/internal/slides/app.go |
| @@ -102,7 +102,7 @@ func New(d *db.DB, cfg Config) (*http.ServeMux, *app, error) { |
| r.Post("/auth/verify", h.LocalGuard(authPlugin.Verify)) |
| r.Post("/signout", h.Signout) |
| r.Get("/signed-out", h.SignedOut) |
| - r.Get(connect.LocalCompletePath, h.LocalComplete) |
| + r.Get(connect.LocalCompletePath, a.homeLocalComplete) |
| r.Get(handoff.StartPath, a.home.Start) |
| r.Post(handoff.CallbackPath, a.home.Callback) |
| r.Get(handoff.FinishPath, a.home.Finish) |
diff --git a/internal/slides/home.go b/internal/slides/home.go| index 5c70636..b9221a8 100644 |
| --- a/internal/slides/home.go |
| +++ b/internal/slides/home.go |
| @@ -7,6 +7,7 @@ import ( |
| "errors" |
| "fmt" |
| "net/http" |
| + "time" |
| "amadan.net/oficina/home/connect" |
| "amadan.net/oficina/home/connect/linkstore" |
| @@ -175,3 +176,31 @@ func restoreExportPrincipal(r *http.Request) *http.Request { |
| } |
| return r |
| } |
| + |
| +// homeLocalComplete is GET /auth/local/complete with Home configured: where |
| +// a local sign-in lands. After an Oficina assertion Slides had no link for, |
| +// connect resumes the link from here, and that needs the person's users |
| +// row. A first-ever local sign-in has none yet (currentUser creates it on |
| +// the first page), so the resume fell to /account/home, which answered 403 |
| +// (Astra's review of #23). A fresh, admitted local session gets its row |
| +// here first, exactly as currentUser would make it, sample deck included; |
| +// any other request is passed on untouched. Failing costs only the |
| +// shortcut: the sign-in itself has already succeeded. |
| +func (a *app) homeLocalComplete(w http.ResponseWriter, r *http.Request) { |
| + if s, ok := a.homeSessions.From(r); ok && (s.Method == "magiclink" || s.Method == "keymail") && a.allowed.allows(s.Subject) { |
| + if _, fresh := connect.FreshLocal(neutralSession(s), time.Now()); fresh { |
| + u, created, err := ensureUser(r.Context(), a.db.G, s.Subject) |
| + switch { |
| + case err != nil: |
| + a.logger.Error("slides: create user before resuming a Home link", "err", err) |
| + case created: |
| + if has, err := hasDeck(r.Context(), a.db.G, u); err != nil { |
| + a.logger.Error("slides: check for an existing deck before seeding", "user", u.ID, "err", err) |
| + } else if !has { |
| + a.seedSampleDeckFor(r.Context(), u) |
| + } |
| + } |
| + } |
| + } |
| + a.homeRoutes.LocalComplete(w, r) |
| +} |
diff --git a/internal/slides/home_menu_test.go b/internal/slides/home_menu_test.go| index 08bf757..168e7af 100644 |
| --- a/internal/slides/home_menu_test.go |
| +++ b/internal/slides/home_menu_test.go |
| @@ -229,6 +229,31 @@ func TestHomeMenuConnectThenAccountsConnectedAndItemGone(t *testing.T) { |
| // through a fresh Home assertion and the explicit confirm. |
| func TestHomeUnknownAssertionResumesLinkAfterLocalSignIn(t *testing.T) { |
| b, u := newHomeBrowser(t) |
| + b.unknownThenResume(t, u.Email, u.ID) |
| +} |
| + |
| +// TestHomeUnknownAssertionResumesForAFirstLocalSignIn is the same flow for |
| +// an admitted address with no users row yet (Astra's review of #23): the |
| +// first local sign-in must create the row before connect resumes, or the |
| +// resume falls to /account/home and that page answers 403. |
| +func TestHomeUnknownAssertionResumesForAFirstLocalSignIn(t *testing.T) { |
| + b, u := newHomeBrowser(t) |
| + if err := b.a.db.G.Delete(&User{}, u.ID).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + b.unknownThenResume(t, u.Email, 0) |
| + var created User |
| + if err := b.a.db.G.Where("email = ?", u.Email).Take(&created).Error; err != nil || created.ID == u.ID { |
| + t.Fatal("first local sign-in did not create its own users row", created, err) |
| + } |
| +} |
| + |
| +// unknownThenResume runs an unknown Oficina arrival, a local sign-in as |
| +// email, the resumed fresh exchange and the explicit confirm, and checks |
| +// the link is stored only after the confirm, against the person signed in |
| +// (id, or any row with that address when id is 0). |
| +func (b *homeBrowser) unknownThenResume(t *testing.T, email string, id int64) { |
| + t.Helper() |
| front := b.get("/signin") |
| if front.Code != 303 { |
| t.Fatal("front door", front.Code, front.Header()) |
| @@ -245,7 +270,7 @@ func TestHomeUnknownAssertionResumesLinkAfterLocalSignIn(t *testing.T) { |
| if b.get("/signin/local").Code != 200 { |
| t.Fatal("local sign-in form") |
| } |
| - verify := b.localSignIn(u.Email) |
| + verify := b.localSignIn(email) |
| if verify.Code != 303 || verify.Header().Get("Location") != connect.LocalCompletePath { |
| t.Fatal("local verify", verify.Code, verify.Header()) |
| } |
| @@ -275,7 +300,7 @@ func TestHomeUnknownAssertionResumesLinkAfterLocalSignIn(t *testing.T) { |
| if post.Code != 303 || !strings.Contains(post.Header().Get("Location"), "connected=1") { |
| t.Fatal("confirm", post.Code, post.Header()) |
| } |
| - if person, err := b.a.home.Resolve(t.Context(), "unlinked-home-person"); err != nil || person.ID != u.ID { |
| + if person, err := b.a.home.Resolve(t.Context(), "unlinked-home-person"); err != nil || person.Label != email || (id != 0 && person.ID != id) { |
| t.Fatal("resumed link not stored", person, err) |
| } |
| if b.linkRows() != 1 { |