Skip to content

relayfile login only refreshes one of two credential files #188

@khaliqgant

Description

@khaliqgant

Summary

relayfile login writes to exactly one credentials file depending on which sub-flow runs, never both. Operators who use the cloud browser flow get a fresh cloud-credentials.json but a stale credentials.json; operators who pass --token / --api-key get the opposite. Any consumer reading the "wrong" file after a re-login holds stale auth, which is the same failure mode that motivated #178 / #179.

Field shape on disk today:

  • ~/.relayfile/credentials.json: server, token, updatedAt (single bearer)
  • ~/.relayfile/cloud-credentials.json: apiUrl, accessToken, accessTokenExpiresAt, refreshToken, refreshTokenExpiresAt, updatedAt (full OAuth session, separate updatedAt)

Observed on one machine after a single relayfile login:

  • credentials.json mtime: May 21 13:32:06 2026
  • cloud-credentials.json mtime: May 21 13:31:25 2026

The two files drift on every login, confirming they are not co-refreshed.

Code references

  • cmd/relayfile-cli/main.go:1782runLogin entry point
  • cmd/relayfile-cli/main.go:1816--token path calls loginWithAPIKey only
  • cmd/relayfile-cli/main.go:1829--api-key interactive path calls loginWithAPIKey only
  • cmd/relayfile-cli/main.go:1837 — default cloud-browser path calls ensureCloudCredentials only
  • cmd/relayfile-cli/main.go:895ensureCloudCredentialssaveCloudCredentials (writes cloud-credentials.json only)
  • cmd/relayfile-cli/main.go:1870loginWithAPIKeysaveCredentials (writes credentials.json only)
  • cmd/relayfile-cli/main_test.go:2672 references a prior bug "where relayfile login only refreshed cloud-credentials.json even when a workspace was already registered locally" — that test guards the workspace token but not this credentials.jsoncloud-credentials.json split.

Expected vs Actual

  • Expected: After any successful relayfile login, both credential files reflect the new session (or one file becomes the canonical source and the other is removed / treated as cache).
  • Actual: Exactly one file is rewritten; the other is left at its prior updatedAt. Daemons/tools reading the stale file behave as if no re-login occurred.

Suggested fix direction

  • Co-write: in the cloud-browser path, after ensureCloudCredentials, also derive and persist a credentials.json entry pointing at the cloud-issued bearer (or invalidate credentials.json so callers fall through to the cloud session).
  • Symmetric in loginWithAPIKey: if a cloud session exists, refuse silently overwriting it, or clear it.
  • Add a test that asserts both file mtimes advance after a single relayfile login invocation in each mode.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions