Skip to content

fix(jac-client): jacLogin/jacSignup use identity/credential shape#5602

Open
kashmithnisakya wants to merge 16 commits intojaseci-labs:mainfrom
kashmithnisakya:jac-client/identity-auth-shape
Open

fix(jac-client): jacLogin/jacSignup use identity/credential shape#5602
kashmithnisakya wants to merge 16 commits intojaseci-labs:mainfrom
kashmithnisakya:jac-client/identity-auth-shape

Conversation

@kashmithnisakya
Copy link
Copy Markdown
Collaborator

Description

  • jacLogin and jacSignup were still POSTing {username, password}, which jac-scale no longer accepts. They now send {identity: {type, value}, credential: {type, password}} (plural identities for signup).
  • Adds Identity and Credential types, exported from @jac/runtime, for explicit typed calls like jacLogin(Identity.email("a@b.com"), Credential.password("pw")).
  • Existing 2-arg calls (jacLogin("alice", "pw")) keep working — strings are auto-wrapped, so no example/template/product code needs to change.

kashmithnisakya and others added 16 commits April 17, 2026 21:26
…l types for improved authentication structure
…/jacSignup

The ECMAScript codegen pass (emit_isinstance in primitives_es.impl.jac)
cannot resolve user-defined obj classes as the second arg of isinstance(),
causing IndexError during PWA bundle transpilation.

Restructure the branching to use isinstance(x, str) and isinstance(x, list)
only — both are builtins the JS pass handles. Behavior is unchanged: strings
are auto-wrapped, lists are mapped, everything else is assumed to be an
Identity/Credential instance and passed through unchanged.
…h helpers

The ECMAScript codegen's emit_isinstance is naive (args[0] + ' instanceof ' +
args[1]) and fails whenever args[1] isn't a resolvable JS class name. This
breaks for both user-defined obj classes (Identity, Credential) and builtin
primitives (str, list) — IndexError: list index out of range during PWA
bundle transpilation.

Restructure jacLogin / jacSignup to use the pattern already established in
jac/jaclang/runtimelib/impl/client_runtime.impl.jac:
  - Array.isArray(x)           replaces isinstance(x, list)
  - __isString(x)              replaces isinstance(x, str)  (new helper,
                               mirrors the existing __isObject / __isFunction
                               built on Object.prototype.toString.call)
  - identity.to_dict truthy    replaces isinstance(x, Identity)
                               (positive duck-type check: presence of the
                               method we're about to call)

Each dispatch branch is now positively identified. Unknown inputs raise
ValueError with an explicit message instead of crashing later at
undefined.to_dict() or silently sending the wrong wire shape.
…block scope

Browser e2e tests fail with 'ReferenceError: identities is not defined' and
'ReferenceError: ident is not defined' because the Jac -> JS transpiler emits
each branch of an if/elif/else as a block-scoped 'let' declaration. Variables
assigned only inside the branches are invisible when used afterwards.

Move the per-input dispatch into two new static methods that use early
return (which compiles cleanly to function-scoped JS):

  Identity.from_any(value)    str -> Identity.auto(), Identity passthrough,
                              else raise ValueError
  Credential.from_any(value)  str -> Credential.password(), Credential
                              passthrough, else raise ValueError

jacLogin then becomes a straight two-liner:
    ident = Identity.from_any(identity);
    cred = Credential.from_any(credential);

jacSignup does list-normalization via a single ternary, then maps to_dict:
    identity_list = identity if Array.isArray(identity) else
                    [Identity.from_any(identity)];
    identities = [i.to_dict() for i in identity_list];
    cred = Credential.from_any(credential);

All dispatch results live in function scope from their first assignment, so
the block-scoping issue goes away.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant