-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from Giveth/feature_add_admin_for_multisig_ses…
…sion add multisig session admin tab
- Loading branch information
Showing
4 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Admin, AdminRole } from '@/src/entities/admin'; | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
const bcrypt = require('bcrypt'); | ||
|
||
export class addDefaultAdminUser1701273095150 implements MigrationInterface { | ||
private defaultAdminEmail = '[email protected]'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
const isStagingOrLocal = | ||
process.env.ENVIRONMENT === 'local' || | ||
process.env.ENVIRONMENT === 'staging' || | ||
process.env.ENVIRONMENT === 'develop'; | ||
|
||
if (isStagingOrLocal) { | ||
const defaultAdmin = new Admin(); | ||
defaultAdmin.email = this.defaultAdminEmail; | ||
const hash = await bcrypt.hash( | ||
'password', | ||
Number(process.env.BCRYPT_SALT), | ||
); | ||
defaultAdmin.encryptedPassword = hash; // Set your default password here | ||
|
||
// Assign a default role if needed | ||
defaultAdmin.role = AdminRole.ADMIN; | ||
|
||
await queryRunner.manager.save(defaultAdmin); | ||
} | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.manager | ||
.createQueryBuilder() | ||
.delete() | ||
.from(Admin) | ||
.where('email = :email', { email: this.defaultAdminEmail }) | ||
.execute(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters