Skip to content

Commit

Permalink
rename flag, add to unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
rotorsoft committed Dec 23, 2024
1 parent 6362be4 commit b735202
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions libs/model/src/user/SignIn.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export function SignIn(): Command<typeof schemas.SignIn> {
const { base, encodedAddress, ss58Prefix, hex, existingHexUserId } = actor
.user.auth as VerifiedAddress;

const signed_in = actor.user.id > 0;
let user_id = signed_in ? actor.user.id : (existingHexUserId ?? null);
const was_signed_in = actor.user.id > 0;
let user_id = was_signed_in ? actor.user.id : (existingHexUserId ?? null);

await verifySessionSignature(
deserializeCanvas(session),
Expand Down Expand Up @@ -199,7 +199,7 @@ export function SignIn(): Command<typeof schemas.SignIn> {
...addr.toJSON(),
community_base: base,
community_ss58_prefix: ss58Prefix,
signed_in,
was_signed_in,
user_created,
address_created,
first_community,
Expand Down
3 changes: 3 additions & 0 deletions libs/model/test/user/signin-lifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ describe('SignIn Lifecycle', async () => {
expect(addr!.verification_token).to.be.not.null;
expect(addr!.verified).to.be.not.null;

expect(addr!.was_signed_in).to.be.false;
expect(addr!.first_community).to.be.true;
expect(addr!.user_created).to.be.true;
expect(addr!.address_created).to.be.true;
Expand Down Expand Up @@ -160,6 +161,7 @@ describe('SignIn Lifecycle', async () => {

expect(addr!).to.not.be.null;
expect(addr!.User).to.be.not.null;
expect(addr!.was_signed_in).to.be.true;
expect(addr!.first_community).to.be.false;
expect(addr!.user_created).to.be.false;
expect(addr!.address_created).to.be.false;
Expand Down Expand Up @@ -315,6 +317,7 @@ describe('SignIn Lifecycle', async () => {
},
});
expect(transferred).to.not.be.null;
expect(transferred!.was_signed_in).to.be.true;
expect(transferred!.address).to.be.equal(ref.address);

// check that user 2 now owns 2 addresses from user 1
Expand Down
2 changes: 1 addition & 1 deletion libs/schemas/src/commands/user.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const SignIn = {
output: Address.extend({
community_base: z.nativeEnum(ChainBase),
community_ss58_prefix: z.number().nullish(),
signed_in: z.boolean().describe('True when user was already signed in'),
was_signed_in: z.boolean().describe('True when user was already signed in'),
user_created: z
.boolean()
.describe(
Expand Down
7 changes: 5 additions & 2 deletions packages/commonwealth/server/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export const trpcRouter = trpc.router({
signIn: trpc.command(User.SignIn, trpc.Tag.User, [
async (input, output, ctx) => {
await new Promise((resolve, reject) => {
if (output.signed_in) return resolve(true);
// no need to login if we're already signed in
if (output.was_signed_in) return resolve(true);

// complete passport login
ctx.req.login(output.User as Express.User, (err) => {
if (err) {
analytics().track(
Expand All @@ -33,7 +36,7 @@ export const trpcRouter = trpc.router({
MixpanelUserSignupEvent.NEW_USER_SIGNUP,
{ community_id: output.community_id },
]
: !output.signed_in
: !output.was_signed_in
? [
MixpanelLoginEvent.LOGIN_COMPLETED,
{
Expand Down

0 comments on commit b735202

Please sign in to comment.