-
Notifications
You must be signed in to change notification settings - Fork 5
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 #182 from chingu-x/dev
Merge into main for alpha test
- Loading branch information
Showing
24 changed files
with
874 additions
and
60 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
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
45 changes: 45 additions & 0 deletions
45
prisma/migrations/20240812035737_add_oauth_tables/migration.sql
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,45 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `discordId` on the `User` table. All the data in the column will be lost. | ||
- You are about to drop the column `githubId` on the `User` table. All the data in the column will be lost. | ||
- You are about to drop the column `linkedinId` on the `User` table. All the data in the column will be lost. | ||
- You are about to drop the column `twitterId` on the `User` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "User" DROP COLUMN "discordId", | ||
DROP COLUMN "githubId", | ||
DROP COLUMN "linkedinId", | ||
DROP COLUMN "twitterId"; | ||
|
||
-- CreateTable | ||
CREATE TABLE "OAuthProvider" ( | ||
"id" SERIAL NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "OAuthProvider_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "UserOAuthProfile" ( | ||
"userId" UUID NOT NULL, | ||
"providerId" INTEGER NOT NULL, | ||
"providerUserId" TEXT NOT NULL, | ||
"providerUsername" TEXT, | ||
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "UserOAuthProfile_pkey" PRIMARY KEY ("userId","providerId") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "UserOAuthProfile_providerId_providerUserId_key" ON "UserOAuthProfile"("providerId", "providerUserId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UserOAuthProfile" ADD CONSTRAINT "UserOAuthProfile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UserOAuthProfile" ADD CONSTRAINT "UserOAuthProfile_providerId_fkey" FOREIGN KEY ("providerId") REFERENCES "OAuthProvider"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
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,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "postgresql" |
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,23 @@ | ||
import { prisma } from "./prisma-client"; | ||
|
||
const populateOAuthProviders = async () => { | ||
await prisma.oAuthProvider.createMany({ | ||
data: [ | ||
{ | ||
name: "discord", | ||
}, | ||
{ | ||
name: "github", | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
const populateOAuthUserProfiles = async () => {}; | ||
|
||
export const populateOAuth = async () => { | ||
await populateOAuthProviders(); | ||
await populateOAuthUserProfiles(); | ||
}; | ||
|
||
console.log("OAuth Providers and userProfile populated"); |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { IAuthProvider } from "../global/interfaces/oauth.interface"; | ||
import { PrismaService } from "../prisma/prisma.service"; | ||
import { DiscordUser } from "../global/types/auth.types"; | ||
|
||
@Injectable() | ||
export class DiscordAuthService implements IAuthProvider { | ||
constructor(private prisma: PrismaService) {} | ||
async validateUser(user: DiscordUser) { | ||
const userInDb = await this.prisma.findUserByOAuthId( | ||
"discord", | ||
user.discordId, | ||
); | ||
console.log( | ||
`discord-auth.service.ts (14): userInDb = ${JSON.stringify(userInDb)}`, | ||
); | ||
} | ||
|
||
createUser() {} | ||
|
||
findUserById() {} | ||
} |
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,14 @@ | ||
import { ExecutionContext, Injectable } from "@nestjs/common"; | ||
import { AuthGuard } from "@nestjs/passport"; | ||
|
||
@Injectable() | ||
export class DiscordAuthGuard extends AuthGuard("discord") { | ||
async canActivate(context: ExecutionContext): Promise<boolean> { | ||
const activate = (await super.canActivate(context)) as boolean; | ||
console.log(`discord-auth.guard.ts (8): activate = ${activate}`); | ||
const request = context.switchToHttp().getRequest(); | ||
console.log(`discord-auth.guard.ts (10): request = ${request}`); | ||
await super.logIn(request); | ||
return activate; | ||
} | ||
} |
Oops, something went wrong.