-
Notifications
You must be signed in to change notification settings - Fork 0
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 #11 from Open-SGF/feat/auth-endpoints
WIP auth endpoints
- Loading branch information
Showing
14 changed files
with
446 additions
and
280 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ DB_USER= | |
DB_PASSWORD= | ||
DB_NAME=portal_to_work | ||
DB_LOGGING=true | ||
GOOGLE_RECAPTCHA_SECRET_KEY= |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules | ||
build | ||
.env | ||
.idea/ | ||
.idea | ||
.vscode |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddOccupations1638839975840 implements MigrationInterface { | ||
name = 'AddOccupations1638839975840' | ||
name = 'AddOccupations1638839975840'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`CREATE TABLE "occupations" ("id" SERIAL NOT NULL, "title" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_0bf09083dd897df1e8ebb96b5c1" PRIMARY KEY ("id"))`); | ||
await queryRunner.query( | ||
`CREATE TABLE "occupations" ("id" SERIAL NOT NULL, "title" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_0bf09083dd897df1e8ebb96b5c1" PRIMARY KEY ("id"))`, | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP TABLE "occupations"`); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,20 +1,33 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddJobs1638841344534 implements MigrationInterface { | ||
name = 'AddJobs1638841344534' | ||
name = 'AddJobs1638841344534'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`CREATE TABLE "jobs" ("id" SERIAL NOT NULL, "title" character varying NOT NULL, "description" text NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "occupationId" integer, "companyId" integer, "locationId" integer, CONSTRAINT "PK_cf0a6c42b72fcc7f7c237def345" PRIMARY KEY ("id"))`); | ||
await queryRunner.query(`ALTER TABLE "jobs" ADD CONSTRAINT "FK_7157538b49480e6f51a61c35bb1" FOREIGN KEY ("occupationId") REFERENCES "occupations"("id") ON DELETE SET NULL ON UPDATE CASCADE`); | ||
await queryRunner.query(`ALTER TABLE "jobs" ADD CONSTRAINT "FK_6ce4483dc65ed9d2e171269d801" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE`); | ||
await queryRunner.query(`ALTER TABLE "jobs" ADD CONSTRAINT "FK_5dbffa782dc6074a7e4cb39150d" FOREIGN KEY ("locationId") REFERENCES "locations"("id") ON DELETE SET NULL ON UPDATE CASCADE`); | ||
await queryRunner.query( | ||
`CREATE TABLE "jobs" ("id" SERIAL NOT NULL, "title" character varying NOT NULL, "description" text NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "occupationId" integer, "companyId" integer, "locationId" integer, CONSTRAINT "PK_cf0a6c42b72fcc7f7c237def345" PRIMARY KEY ("id"))`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "jobs" ADD CONSTRAINT "FK_7157538b49480e6f51a61c35bb1" FOREIGN KEY ("occupationId") REFERENCES "occupations"("id") ON DELETE SET NULL ON UPDATE CASCADE`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "jobs" ADD CONSTRAINT "FK_6ce4483dc65ed9d2e171269d801" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "jobs" ADD CONSTRAINT "FK_5dbffa782dc6074a7e4cb39150d" FOREIGN KEY ("locationId") REFERENCES "locations"("id") ON DELETE SET NULL ON UPDATE CASCADE`, | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "jobs" DROP CONSTRAINT "FK_5dbffa782dc6074a7e4cb39150d"`); | ||
await queryRunner.query(`ALTER TABLE "jobs" DROP CONSTRAINT "FK_6ce4483dc65ed9d2e171269d801"`); | ||
await queryRunner.query(`ALTER TABLE "jobs" DROP CONSTRAINT "FK_7157538b49480e6f51a61c35bb1"`); | ||
await queryRunner.query( | ||
`ALTER TABLE "jobs" DROP CONSTRAINT "FK_5dbffa782dc6074a7e4cb39150d"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "jobs" DROP CONSTRAINT "FK_6ce4483dc65ed9d2e171269d801"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "jobs" DROP CONSTRAINT "FK_7157538b49480e6f51a61c35bb1"`, | ||
); | ||
await queryRunner.query(`DROP TABLE "jobs"`); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,18 +1,27 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddEvents1638841899720 implements MigrationInterface { | ||
name = 'AddEvents1638841899720' | ||
name = 'AddEvents1638841899720'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`CREATE TABLE "events" ("id" SERIAL NOT NULL, "title" character varying NOT NULL, "description" text NOT NULL, "link" character varying, "startAt" TIMESTAMP NOT NULL, "endAt" TIMESTAMP NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "companyId" integer, "locationId" integer, CONSTRAINT "PK_40731c7151fe4be3116e45ddf73" PRIMARY KEY ("id"))`); | ||
await queryRunner.query(`ALTER TABLE "events" ADD CONSTRAINT "FK_b42eb62a0da91cc26d953db93cd" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE`); | ||
await queryRunner.query(`ALTER TABLE "events" ADD CONSTRAINT "FK_55ad94f5c1b4c97960d6d7dc115" FOREIGN KEY ("locationId") REFERENCES "locations"("id") ON DELETE SET NULL ON UPDATE CASCADE`); | ||
await queryRunner.query( | ||
`CREATE TABLE "events" ("id" SERIAL NOT NULL, "title" character varying NOT NULL, "description" text NOT NULL, "link" character varying, "startAt" TIMESTAMP NOT NULL, "endAt" TIMESTAMP NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "companyId" integer, "locationId" integer, CONSTRAINT "PK_40731c7151fe4be3116e45ddf73" PRIMARY KEY ("id"))`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "events" ADD CONSTRAINT "FK_b42eb62a0da91cc26d953db93cd" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "events" ADD CONSTRAINT "FK_55ad94f5c1b4c97960d6d7dc115" FOREIGN KEY ("locationId") REFERENCES "locations"("id") ON DELETE SET NULL ON UPDATE CASCADE`, | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "events" DROP CONSTRAINT "FK_55ad94f5c1b4c97960d6d7dc115"`); | ||
await queryRunner.query(`ALTER TABLE "events" DROP CONSTRAINT "FK_b42eb62a0da91cc26d953db93cd"`); | ||
await queryRunner.query( | ||
`ALTER TABLE "events" DROP CONSTRAINT "FK_55ad94f5c1b4c97960d6d7dc115"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "events" DROP CONSTRAINT "FK_b42eb62a0da91cc26d953db93cd"`, | ||
); | ||
await queryRunner.query(`DROP TABLE "events"`); | ||
} | ||
|
||
} |
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
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,51 @@ | ||
import type { FastifyPluginAsync } from 'fastify'; | ||
import { FromSchema } from 'json-schema-to-ts'; | ||
import fetch from 'cross-fetch'; | ||
import { GOOGLE_RECAPTCHA_SECRET_KEY } from '../config'; | ||
|
||
const authBodyParams = { | ||
type: 'object', | ||
properties: { | ||
'g-recaptcha-token': { type: 'string' }, | ||
}, | ||
required: ['g-recaptcha-token'], | ||
} as const; | ||
|
||
const recaptchaVerifyUrl = 'https://www.google.com/recaptcha/api/siteverify'; | ||
|
||
export interface IRecaptchaResponse { | ||
success: boolean; | ||
challenge_ts?: string; | ||
hostname?: string; | ||
error_codes?: string[]; | ||
} | ||
|
||
export const auth: FastifyPluginAsync = async (app) => { | ||
app.route<{ Body: FromSchema<typeof authBodyParams> }>({ | ||
url: '/', | ||
method: 'POST', | ||
schema: { body: authBodyParams }, | ||
handler: async (req, reply) => { | ||
const token = req.body['g-recaptcha-token']; | ||
|
||
const res = await fetch(recaptchaVerifyUrl, { | ||
method: 'POST', | ||
body: new URLSearchParams({ | ||
secret: GOOGLE_RECAPTCHA_SECRET_KEY, | ||
response: token, | ||
}), | ||
}); | ||
|
||
const recaptchaRes = (await res.json()) as IRecaptchaResponse; | ||
|
||
if (!recaptchaRes.success) { | ||
reply.code(401); | ||
return; | ||
} | ||
|
||
return { | ||
token: 'test', | ||
}; | ||
}, | ||
}); | ||
}; |