Skip to content

Commit

Permalink
remove WalletSsoSource from address model
Browse files Browse the repository at this point in the history
  • Loading branch information
timolegros committed Sep 7, 2024
1 parent 063ef3c commit 6300654
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 36 deletions.
1 change: 0 additions & 1 deletion libs/model/src/models/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export default (
defaultValue: false,
},
wallet_id: { type: Sequelize.STRING, allowNull: true },
wallet_sso_source: { type: Sequelize.STRING, allowNull: true },
block_info: { type: Sequelize.STRING, allowNull: true },
is_banned: {
type: Sequelize.BOOLEAN,
Expand Down
5 changes: 1 addition & 4 deletions libs/schemas/src/entities/user.schemas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Roles, WalletId, WalletSsoSource } from '@hicommonwealth/shared';
import { Roles, WalletId } from '@hicommonwealth/shared';
import { z } from 'zod';
import { PG_INT } from '../utils';

Expand Down Expand Up @@ -61,9 +61,6 @@ export const Address = z.object({
block_info: z.string().max(255).nullish(),
is_user_default: z.boolean().default(false),
role: z.enum(Roles).default('member'),
wallet_sso_source: z
.union([z.nativeEnum(WalletSsoSource), z.literal('')])
.nullish(),
is_banned: z.boolean().default(false),
hex: z.string().max(64).nullish(),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.query(`
UPDATE "Addresses"
SET wallet_sso_source = NULL
WHERE wallet_sso_source = '';
`);
await queryInterface.removeColumn('Addresses', 'wallet_sso_source');
},

async down(queryInterface, Sequelize) {},
Expand Down
26 changes: 1 addition & 25 deletions packages/commonwealth/server/passport/magic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
CANVAS_TOPIC,
ChainBase,
WalletId,
WalletSsoSource,
deserializeCanvas,
getSessionSignerForAddress,
} from '@hicommonwealth/shared';
Expand All @@ -37,7 +36,6 @@ type MagicLoginContext = {
existingUserInstance?: UserInstance;
loggedInUser?: UserInstance;
profileMetadata?: { username?: string; avatarUrl?: string };
walletSsoSource: WalletSsoSource;
};

const DEFAULT_ETH_COMMUNITY_ID = 'ethereum';
Expand All @@ -47,7 +45,6 @@ async function createMagicAddressInstances(
models: DB,
generatedAddresses: Array<{ address: string; community_id: string }>,
user: UserAttributes,
walletSsoSource: WalletSsoSource,
decodedMagicToken: MagicUser,
t?: Transaction,
): Promise<AddressInstance[]> {
Expand Down Expand Up @@ -91,16 +88,6 @@ async function createMagicAddressInstances(
if (!created) {
// Update used magic token to prevent replay attacks
addressInstance.verification_token = decodedMagicToken.claim.tid;

if (
addressInstance.wallet_sso_source === WalletSsoSource.Unknown ||
// set wallet_sso_source if it was unknown before
addressInstance.wallet_sso_source === undefined ||
addressInstance.wallet_sso_source === null
) {
addressInstance.wallet_sso_source = walletSsoSource;
}

await addressInstance.save({ transaction: t });
}
addressInstances.push(addressInstance);
Expand All @@ -115,7 +102,6 @@ async function createNewMagicUser({
magicUserMetadata,
generatedAddresses,
profileMetadata,
walletSsoSource,
}: MagicLoginContext): Promise<UserInstance> {
// completely new user: create user, profile, addresses
return sequelize.transaction(async (transaction) => {
Expand Down Expand Up @@ -151,7 +137,6 @@ async function createNewMagicUser({
models,
generatedAddresses,
newUser,
walletSsoSource,
decodedMagicToken,
transaction,
);
Expand Down Expand Up @@ -235,7 +220,6 @@ async function loginExistingMagicUser({
existingUserInstance,
decodedMagicToken,
generatedAddresses,
walletSsoSource,
}: MagicLoginContext): Promise<UserInstance> {
if (!existingUserInstance) {
throw new Error('No user provided to sign in');
Expand Down Expand Up @@ -273,7 +257,6 @@ async function loginExistingMagicUser({
models,
generatedAddresses,
existingUserInstance,
walletSsoSource,
decodedMagicToken,
transaction,
);
Expand Down Expand Up @@ -346,15 +329,12 @@ async function addMagicToUser({
generatedAddresses,
loggedInUser,
decodedMagicToken,
walletSsoSource,
}: MagicLoginContext): Promise<UserInstance> {
// create new address on logged-in user
const addressInstances = await createMagicAddressInstances(
models,
generatedAddresses,
// @ts-expect-error StrictNullChecks
loggedInUser,
walletSsoSource,
loggedInUser!,
decodedMagicToken,
);

Expand Down Expand Up @@ -386,15 +366,13 @@ async function magicLoginRoute(
signature: string;
session?: string;
magicAddress?: string; // optional because session keys are feature-flagged
walletSsoSource: WalletSsoSource;
}>,
decodedMagicToken: MagicUser,
cb: DoneFunc,
) {
log.trace(`MAGIC TOKEN: ${JSON.stringify(decodedMagicToken, null, 2)}`);
let communityToJoin: CommunityInstance, error, loggedInUser: UserInstance;

const walletSsoSource = req.body.walletSsoSource;
const generatedAddresses = [
{
address: decodedMagicToken.publicAddress,
Expand Down Expand Up @@ -596,7 +574,6 @@ async function magicLoginRoute(
models,
generatedAddresses,
loggedInUser,
walletSsoSource,
decodedMagicToken,
);
return cb(null, existingUserInstance);
Expand All @@ -616,7 +593,6 @@ async function magicLoginRoute(
username: req.body.username,
avatarUrl: req.body.avatarUrl,
},
walletSsoSource,
};
try {
// @ts-expect-error StrictNullChecks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ const linkExistingAddressToCommunity = async (
verification_token_expires: verificationTokenExpires,
verified: originalAddress.verified,
wallet_id: originalAddress.wallet_id,
wallet_sso_source: originalAddress.wallet_sso_source,
last_active: new Date(),
role: 'member',
is_user_default: false,
Expand Down

0 comments on commit 6300654

Please sign in to comment.