Skip to content

Commit

Permalink
feat: remove legacy auth0 user accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Dec 2, 2024
1 parent c273883 commit c0a9118
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 166 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { type MigrationExecutor } from '../pg-migrator';

export default {
name: '2024.12.02T00-00-00.legacy-user-org-cleanup.ts',
async run({ sql, connection }) {
// Delete all the organizations owned by a legacy user
await connection.query(sql`
DELETE
FROM
"organizations"
WHERE
"user_id" = ANY(
SELECT
"id"
FROM
"users"
WHERE
"supertoken_user_id" IS NULL
)
`);

// Delete all the legacy users
await connection.query(sql`
DELETE
FROM
"users"
WHERE
"supertoken_user_id" IS NULL
`);
},
} satisfies MigrationExecutor;
1 change: 1 addition & 0 deletions packages/migrations/src/run-pg-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,6 @@ export const runPGMigrations = async (args: { slonik: DatabasePool; runTo?: stri
await import('./actions/2024.11.12T00-00-00.supertokens-9.1'),
await import('./actions/2024.11.12T00-00-00.supertokens-9.2'),
await import('./actions/2024.11.12T00-00-00.supertokens-9.3'),
await import('./actions/2024.12.02T00-00-00.legacy-user-org-cleanup'),
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,8 @@ export class SchemaManager {
return null;
}

return this.storage.getOrganizationUser({
organizationId: args.organizationId,
userId: args.userId,
return this.storage.getUserById({
id: args.userId,
});
}

Expand Down
6 changes: 0 additions & 6 deletions packages/services/api/src/modules/shared/providers/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export interface Storage {
isReady(): Promise<boolean>;
ensureUserExists(_: {
superTokensUserId: string;
externalAuthUserId?: string | null;
email: string;
oidcIntegration: null | {
id: string;
Expand Down Expand Up @@ -848,11 +847,6 @@ export interface Storage {

getTargetBreadcrumbForTargetId(_: { targetId: string }): Promise<TargetBreadcrumb | null>;

/**
* Get an user that belongs to a specific organization by id.
*/
getOrganizationUser(_: { organizationId: string; userId: string }): Promise<User | null>;

// Zendesk
setZendeskUserId(_: { userId: string; zendeskId: string }): Promise<void>;
setZendeskOrganizationId(_: { organizationId: string; zendeskId: string }): Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion packages/services/api/src/shared/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export interface Organization {
appDeployments: boolean;
};
zendeskId: string | null;
ownerId: string;
}

export interface OrganizationInvitation {
Expand Down Expand Up @@ -330,7 +331,6 @@ export interface User {
provider: AuthProvider;
superTokensUserId: string | null;
isAdmin: boolean;
externalAuthUserId: string | null;
oidcIntegrationId: string | null;
zendeskId: string | null;
}
Expand Down
Loading

0 comments on commit c0a9118

Please sign in to comment.