Fix external service authentication (#4846)

This commit is contained in:
Satsuki Yanagi 2019-05-03 18:38:19 +09:00 committed by syuilo
parent ddc3ef4cad
commit 82da4d66f2
5 changed files with 35 additions and 24 deletions

View File

@ -0,0 +1,23 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class UserProfile1556746559567 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`UPDATE "user_profile" SET github = FALSE`);
await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "githubId"`);
await queryRunner.query(`ALTER TABLE "user_profile" ADD COLUMN "githubId" VARCHAR(64)`);
await queryRunner.query(`UPDATE "user_profile" SET discord = FALSE`);
await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "discordExpiresDate"`);
await queryRunner.query(`ALTER TABLE "user_profile" ADD COLUMN "discordExpiresDate" VARCHAR(64)`);
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`UPDATE "user_profile" SET github = FALSE`);
await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "githubId"`);
await queryRunner.query(`ALTER TABLE "user_profile" ADD COLUMN "githubId" INTEGER`);
await queryRunner.query(`UPDATE "user_profile" SET discord = FALSE`);
await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "discordExpiresDate"`);
await queryRunner.query(`ALTER TABLE "user_profile" ADD COLUMN "discordExpiresDate" INTEGER`);
}
}

View File

@ -144,10 +144,10 @@ export class UserProfile {
}) })
public githubAccessToken: string | null; public githubAccessToken: string | null;
@Column('integer', { @Column('varchar', {
nullable: true, default: null, length: 64, nullable: true, default: null,
}) })
public githubId: number | null; public githubId: string | null;
@Column('varchar', { @Column('varchar', {
length: 64, nullable: true, default: null, length: 64, nullable: true, default: null,
@ -169,10 +169,10 @@ export class UserProfile {
}) })
public discordRefreshToken: string | null; public discordRefreshToken: string | null;
@Column('integer', { @Column('varchar', {
nullable: true, default: null, length: 64, nullable: true, default: null,
}) })
public discordExpiresDate: number | null; public discordExpiresDate: string | null;
@Column('varchar', { @Column('varchar', {
length: 64, nullable: true, default: null, length: 64, nullable: true, default: null,

View File

@ -203,12 +203,8 @@ router.get('/dc/cb', async ctx => {
} }
const profile = await UserProfiles.createQueryBuilder() const profile = await UserProfiles.createQueryBuilder()
.where('discord @> :discord', { .where('"discordId" = :id', { id: id })
discord: { .andWhere('"userHost" IS NULL')
id: id,
},
})
.andWhere('userHost IS NULL')
.getOne(); .getOne();
if (profile == null) { if (profile == null) {

View File

@ -193,12 +193,8 @@ router.get('/gh/cb', async ctx => {
} }
const link = await UserProfiles.createQueryBuilder() const link = await UserProfiles.createQueryBuilder()
.where('github @> :github', { .where('"githubId" = :id', { id: id })
github: { .andWhere('"userHost" IS NULL')
id: id,
},
})
.andWhere('userHost IS NULL')
.getOne(); .getOne();
if (link == null) { if (link == null) {

View File

@ -141,12 +141,8 @@ router.get('/tw/cb', async ctx => {
const result = await twAuth!.done(JSON.parse(twCtx), ctx.query.oauth_verifier); const result = await twAuth!.done(JSON.parse(twCtx), ctx.query.oauth_verifier);
const link = await UserProfiles.createQueryBuilder() const link = await UserProfiles.createQueryBuilder()
.where('twitter @> :twitter', { .where('"twitterUserId" = :id', { id: result.userId })
twitter: { .andWhere('"userHost" IS NULL')
userId: result.userId,
},
})
.andWhere('userHost IS NULL')
.getOne(); .getOne();
if (link == null) { if (link == null) {