- implement disable_email_auth env var

- add sync crowdin translations github action
This commit is contained in:
Amruth Pillai
2023-11-21 09:44:37 +01:00
parent 635f743e56
commit 1825fc3283
84 changed files with 2693 additions and 2341 deletions

View File

@ -106,6 +106,12 @@ export class AuthController {
return this.handleAuthenticationResponse(user, response);
}
@Get("providers")
getAuthProviders() {
return this.authService.getAuthProviders();
}
// OAuth Flows
@ApiTags("OAuth", "GitHub")
@Get("github")
@UseGuards(GitHubGuard)

View File

@ -32,22 +32,6 @@ export class AuthModule {
TwoFactorStrategy,
// OAuth2 Strategies
{
provide: GoogleStrategy,
inject: [ConfigService, UserService],
useFactory: (configService: ConfigService<Config>, userService: UserService) => {
try {
const clientID = configService.getOrThrow("GOOGLE_CLIENT_ID");
const clientSecret = configService.getOrThrow("GOOGLE_CLIENT_SECRET");
const callbackURL = configService.getOrThrow("GOOGLE_CALLBACK_URL");
return new GoogleStrategy(clientID, clientSecret, callbackURL, userService);
} catch (error) {
return new DummyStrategy();
}
},
},
{
provide: GitHubStrategy,
inject: [ConfigService, UserService],
@ -63,6 +47,22 @@ export class AuthModule {
}
},
},
{
provide: GoogleStrategy,
inject: [ConfigService, UserService],
useFactory: (configService: ConfigService<Config>, userService: UserService) => {
try {
const clientID = configService.getOrThrow("GOOGLE_CLIENT_ID");
const clientSecret = configService.getOrThrow("GOOGLE_CLIENT_SECRET");
const callbackURL = configService.getOrThrow("GOOGLE_CALLBACK_URL");
return new GoogleStrategy(clientID, clientSecret, callbackURL, userService);
} catch (error) {
return new DummyStrategy();
}
},
},
],
exports: [AuthService],
};

View File

@ -7,7 +7,7 @@ import {
import { ConfigService } from "@nestjs/config";
import { JwtService } from "@nestjs/jwt";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
import { LoginDto, RegisterDto } from "@reactive-resume/dto";
import { AuthProvidersDto, LoginDto, RegisterDto } from "@reactive-resume/dto";
import { ErrorMessage } from "@reactive-resume/utils";
import * as bcryptjs from "bcryptjs";
import { randomBytes } from "crypto";
@ -171,6 +171,32 @@ export class AuthService {
});
}
getAuthProviders() {
const providers: AuthProvidersDto = [];
if (!this.configService.get("DISABLE_EMAIL_AUTH")) {
providers.push("email");
}
if (
this.configService.get("GITHUB_CLIENT_ID") &&
this.configService.get("GITHUB_CLIENT_SECRET") &&
this.configService.get("GITHUB_CALLBACK_URL")
) {
providers.push("github");
}
if (
this.configService.get("GOOGLE_CLIENT_ID") &&
this.configService.get("GOOGLE_CLIENT_SECRET") &&
this.configService.get("GOOGLE_CALLBACK_URL")
) {
providers.push("google");
}
return providers;
}
// Email Verification Flows
async sendVerificationEmail(email: string) {
try {

View File

@ -6,8 +6,7 @@ export const configSchema = z.object({
// Ports
PORT: z.coerce.number().default(3000),
// Client Port & URL (only for development environments)
__DEV__CLIENT_PORT: z.coerce.number().optional(),
// Client URL (only for development environments)
__DEV__CLIENT_URL: z.string().url().optional(),
// URLs
@ -44,7 +43,10 @@ export const configSchema = z.object({
// Crowdin (Optional)
CROWDIN_PROJECT_ID: z.coerce.number().optional(),
CROWDIN_ACCESS_TOKEN: z.string().optional(),
CROWDIN_PERSONAL_TOKEN: z.string().optional(),
// Email (Optional)
DISABLE_EMAIL_AUTH: z.coerce.boolean().optional().default(false),
// GitHub (OAuth)
GITHUB_CLIENT_ID: z.string().optional(),

View File

@ -35,21 +35,25 @@ export class ContributorsService {
async fetchCrowdinContributors() {
const projectId = this.configService.getOrThrow("CROWDIN_PROJECT_ID");
const accessToken = this.configService.getOrThrow("CROWDIN_ACCESS_TOKEN");
const accessToken = this.configService.getOrThrow("CROWDIN_PERSONAL_TOKEN");
const response = await this.httpService.axiosRef.get(
`https://api.crowdin.com/api/v2/projects/${projectId}/members`,
{ headers: { Authorization: `Bearer ${accessToken}` } },
);
const { data } = response.data as CrowdinContributorsResponse;
try {
const response = await this.httpService.axiosRef.get(
`https://api.crowdin.com/api/v2/projects/${projectId}/members`,
{ headers: { Authorization: `Bearer ${accessToken}` } },
);
const { data } = response.data as CrowdinContributorsResponse;
return data.map(({ data }) => {
return {
id: data.id,
name: data.username,
url: `https://crowdin.com/profile/${data.username}`,
avatar: data.avatarUrl,
} satisfies ContributorDto;
});
return data.map(({ data }) => {
return {
id: data.id,
name: data.username,
url: `https://crowdin.com/profile/${data.username}`,
avatar: data.avatarUrl,
} satisfies ContributorDto;
});
} catch (error) {
return [];
}
}
}

View File

@ -24,7 +24,7 @@ export class TranslationService {
async fetchLanguages() {
try {
const projectId = this.configService.getOrThrow("CROWDIN_PROJECT_ID");
const accessToken = this.configService.getOrThrow("CROWDIN_ACCESS_TOKEN");
const accessToken = this.configService.getOrThrow("CROWDIN_PERSONAL_TOKEN");
const response = await this.httpService.axiosRef.get(
`https://api.crowdin.com/api/v2/projects/${projectId}/languages/progress?limit=100`,