0
Fork 0
mirror of https://github.com/stonith404/pingvin-share.git synced 2025-02-19 01:55:48 -05:00

refactor: run formatter

This commit is contained in:
Elias Schneider 2024-10-15 20:12:09 +02:00
parent 522a041ca1
commit 1e96011793
No known key found for this signature in database
GPG key ID: 07E623B294202B6C
5 changed files with 43 additions and 26 deletions

View file

@ -120,7 +120,7 @@ export class AuthController {
})
@HttpCode(202)
async requestResetPassword(@Param("email") email: string) {
this.authService.requestResetPassword(email);
await this.authService.requestResetPassword(email);
}
@Post("resetPassword")
@ -172,7 +172,9 @@ export class AuthController {
@Req() request: Request,
@Res({ passthrough: true }) response: Response,
) {
const redirectURI = await this.authService.signOut(request.cookies.access_token);
const redirectURI = await this.authService.signOut(
request.cookies.access_token,
);
const isSecure = this.config.get("general.appUrl").startsWith("https");
response.cookie("access_token", "", {

View file

@ -16,12 +16,12 @@ import * as moment from "moment";
import { ConfigService } from "src/config/config.service";
import { EmailService } from "src/email/email.service";
import { PrismaService } from "src/prisma/prisma.service";
import { OAuthService } from "../oauth/oauth.service";
import { GenericOidcProvider } from "../oauth/provider/genericOidc.provider";
import { UserSevice } from "../user/user.service";
import { AuthRegisterDTO } from "./dto/authRegister.dto";
import { AuthSignInDTO } from "./dto/authSignIn.dto";
import { LdapService } from "./ldap.service";
import { GenericOidcProvider } from "../oauth/provider/genericOidc.provider";
import { OAuthService } from "../oauth/oauth.service";
import { UserSevice } from "../user/user.service";
@Injectable()
export class AuthService {
@ -120,10 +120,7 @@ export class AuthService {
async generateToken(user: User, oauth?: { idToken?: string }) {
// TODO: Make all old loginTokens invalid when a new one is created
// Check if the user has TOTP enabled
if (
user.totpVerified &&
!(oauth && this.config.get("oauth.ignoreTotp"))
) {
if (user.totpVerified && !(oauth && this.config.get("oauth.ignoreTotp"))) {
const loginToken = await this.createLoginToken(user.id);
return { loginToken };
@ -163,7 +160,7 @@ export class AuthService {
},
});
await this.emailService.sendResetPasswordEmail(user.email, token);
this.emailService.sendResetPasswordEmail(user.email, token);
}
async resetPassword(token: string, newPassword: string) {
@ -231,7 +228,10 @@ export class AuthService {
if (refreshTokenId) {
const oauthIDToken = await this.prisma.refreshToken
.findFirst({ select: { oauthIDToken: true }, where: { id: refreshTokenId } })
.findFirst({
select: { oauthIDToken: true },
where: { id: refreshTokenId },
})
.then((refreshToken) => refreshToken?.oauthIDToken)
.catch((e) => {
// Ignore error if refresh token doesn't exist
@ -249,16 +249,27 @@ export class AuthService {
const provider = this.oAuthService.availableProviders()[providerName];
let signOutFromProviderSupportedAndActivated = false;
try {
signOutFromProviderSupportedAndActivated = this.config.get(`oauth.${providerName}-signOut`);
signOutFromProviderSupportedAndActivated = this.config.get(
`oauth.${providerName}-signOut`,
);
} catch (_) {
// Ignore error if the provider is not supported or if the provider sign out is not activated
}
if (provider instanceof GenericOidcProvider && signOutFromProviderSupportedAndActivated) {
const configuration = await provider.getConfiguration();
if (configuration.frontchannel_logout_supported && URL.canParse(configuration.end_session_endpoint)) {
if (
provider instanceof GenericOidcProvider &&
signOutFromProviderSupportedAndActivated
) {
const configuration = await provider.getConfiguration();
if (
configuration.frontchannel_logout_supported &&
URL.canParse(configuration.end_session_endpoint)
) {
const redirectURI = new URL(configuration.end_session_endpoint);
redirectURI.searchParams.append("id_token_hint", idTokenHint);
redirectURI.searchParams.append("client_id", this.config.get(`oauth.${providerName}-clientId`));
redirectURI.searchParams.append(
"client_id",
this.config.get(`oauth.${providerName}-clientId`),
);
return redirectURI.toString();
}
}

View file

@ -15,7 +15,8 @@ export class OAuthService {
private config: ConfigService,
@Inject(forwardRef(() => AuthService)) private auth: AuthService,
@Inject("OAUTH_PLATFORMS") private platforms: string[],
@Inject("OAUTH_PROVIDERS") private oAuthProviders: Record<string, OAuthProvider<unknown>>,
@Inject("OAUTH_PROVIDERS")
private oAuthProviders: Record<string, OAuthProvider<unknown>>,
) {}
private readonly logger = new Logger(OAuthService.name);
@ -30,13 +31,15 @@ export class OAuthService {
}
availableProviders(): Record<string, OAuthProvider<unknown>> {
return Object.fromEntries(Object.entries(this.oAuthProviders)
.map(([providerName, provider]) => [
[providerName, provider],
this.config.get(`oauth.${providerName}-enabled`),
])
.filter(([_, enabled]) => enabled)
.map(([provider, _]) => provider));
return Object.fromEntries(
Object.entries(this.oAuthProviders)
.map(([providerName, provider]) => [
[providerName, provider],
this.config.get(`oauth.${providerName}-enabled`),
])
.filter(([_, enabled]) => enabled)
.map(([provider, _]) => provider),
);
}
async status(user: User) {

View file

@ -85,7 +85,7 @@ export class DiscordProvider implements OAuthProvider<DiscordToken> {
if (limitedUsers) {
await this.checkLimitedUsers(user, limitedUsers);
}
return {
provider: "discord",
providerId: user.id,

View file

@ -31,7 +31,8 @@ const signUp = async (email: string, username: string, password: string) => {
const signOut = async () => {
const response = await api.post("/auth/signOut");
if (URL.canParse(response.data?.redirectURI)) window.location.href = response.data.redirectURI;
if (URL.canParse(response.data?.redirectURI))
window.location.href = response.data.redirectURI;
else window.location.reload();
};