Skip to content

Commit 1e96011

Browse files
committed
refactor: run formatter
1 parent 522a041 commit 1e96011

File tree

5 files changed

+43
-26
lines changed

5 files changed

+43
-26
lines changed

backend/src/auth/auth.controller.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class AuthController {
120120
})
121121
@HttpCode(202)
122122
async requestResetPassword(@Param("email") email: string) {
123-
this.authService.requestResetPassword(email);
123+
await this.authService.requestResetPassword(email);
124124
}
125125

126126
@Post("resetPassword")
@@ -172,7 +172,9 @@ export class AuthController {
172172
@Req() request: Request,
173173
@Res({ passthrough: true }) response: Response,
174174
) {
175-
const redirectURI = await this.authService.signOut(request.cookies.access_token);
175+
const redirectURI = await this.authService.signOut(
176+
request.cookies.access_token,
177+
);
176178

177179
const isSecure = this.config.get("general.appUrl").startsWith("https");
178180
response.cookie("access_token", "", {

backend/src/auth/auth.service.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import * as moment from "moment";
1616
import { ConfigService } from "src/config/config.service";
1717
import { EmailService } from "src/email/email.service";
1818
import { PrismaService } from "src/prisma/prisma.service";
19+
import { OAuthService } from "../oauth/oauth.service";
20+
import { GenericOidcProvider } from "../oauth/provider/genericOidc.provider";
21+
import { UserSevice } from "../user/user.service";
1922
import { AuthRegisterDTO } from "./dto/authRegister.dto";
2023
import { AuthSignInDTO } from "./dto/authSignIn.dto";
2124
import { LdapService } from "./ldap.service";
22-
import { GenericOidcProvider } from "../oauth/provider/genericOidc.provider";
23-
import { OAuthService } from "../oauth/oauth.service";
24-
import { UserSevice } from "../user/user.service";
2525

2626
@Injectable()
2727
export class AuthService {
@@ -120,10 +120,7 @@ export class AuthService {
120120
async generateToken(user: User, oauth?: { idToken?: string }) {
121121
// TODO: Make all old loginTokens invalid when a new one is created
122122
// Check if the user has TOTP enabled
123-
if (
124-
user.totpVerified &&
125-
!(oauth && this.config.get("oauth.ignoreTotp"))
126-
) {
123+
if (user.totpVerified && !(oauth && this.config.get("oauth.ignoreTotp"))) {
127124
const loginToken = await this.createLoginToken(user.id);
128125

129126
return { loginToken };
@@ -163,7 +160,7 @@ export class AuthService {
163160
},
164161
});
165162

166-
await this.emailService.sendResetPasswordEmail(user.email, token);
163+
this.emailService.sendResetPasswordEmail(user.email, token);
167164
}
168165

169166
async resetPassword(token: string, newPassword: string) {
@@ -231,7 +228,10 @@ export class AuthService {
231228

232229
if (refreshTokenId) {
233230
const oauthIDToken = await this.prisma.refreshToken
234-
.findFirst({ select: { oauthIDToken: true }, where: { id: refreshTokenId } })
231+
.findFirst({
232+
select: { oauthIDToken: true },
233+
where: { id: refreshTokenId },
234+
})
235235
.then((refreshToken) => refreshToken?.oauthIDToken)
236236
.catch((e) => {
237237
// Ignore error if refresh token doesn't exist
@@ -249,16 +249,27 @@ export class AuthService {
249249
const provider = this.oAuthService.availableProviders()[providerName];
250250
let signOutFromProviderSupportedAndActivated = false;
251251
try {
252-
signOutFromProviderSupportedAndActivated = this.config.get(`oauth.${providerName}-signOut`);
252+
signOutFromProviderSupportedAndActivated = this.config.get(
253+
`oauth.${providerName}-signOut`,
254+
);
253255
} catch (_) {
254256
// Ignore error if the provider is not supported or if the provider sign out is not activated
255257
}
256-
if (provider instanceof GenericOidcProvider && signOutFromProviderSupportedAndActivated) {
257-
const configuration = await provider.getConfiguration();
258-
if (configuration.frontchannel_logout_supported && URL.canParse(configuration.end_session_endpoint)) {
258+
if (
259+
provider instanceof GenericOidcProvider &&
260+
signOutFromProviderSupportedAndActivated
261+
) {
262+
const configuration = await provider.getConfiguration();
263+
if (
264+
configuration.frontchannel_logout_supported &&
265+
URL.canParse(configuration.end_session_endpoint)
266+
) {
259267
const redirectURI = new URL(configuration.end_session_endpoint);
260268
redirectURI.searchParams.append("id_token_hint", idTokenHint);
261-
redirectURI.searchParams.append("client_id", this.config.get(`oauth.${providerName}-clientId`));
269+
redirectURI.searchParams.append(
270+
"client_id",
271+
this.config.get(`oauth.${providerName}-clientId`),
272+
);
262273
return redirectURI.toString();
263274
}
264275
}

backend/src/oauth/oauth.service.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export class OAuthService {
1515
private config: ConfigService,
1616
@Inject(forwardRef(() => AuthService)) private auth: AuthService,
1717
@Inject("OAUTH_PLATFORMS") private platforms: string[],
18-
@Inject("OAUTH_PROVIDERS") private oAuthProviders: Record<string, OAuthProvider<unknown>>,
18+
@Inject("OAUTH_PROVIDERS")
19+
private oAuthProviders: Record<string, OAuthProvider<unknown>>,
1920
) {}
2021
private readonly logger = new Logger(OAuthService.name);
2122

@@ -30,13 +31,15 @@ export class OAuthService {
3031
}
3132

3233
availableProviders(): Record<string, OAuthProvider<unknown>> {
33-
return Object.fromEntries(Object.entries(this.oAuthProviders)
34-
.map(([providerName, provider]) => [
35-
[providerName, provider],
36-
this.config.get(`oauth.${providerName}-enabled`),
37-
])
38-
.filter(([_, enabled]) => enabled)
39-
.map(([provider, _]) => provider));
34+
return Object.fromEntries(
35+
Object.entries(this.oAuthProviders)
36+
.map(([providerName, provider]) => [
37+
[providerName, provider],
38+
this.config.get(`oauth.${providerName}-enabled`),
39+
])
40+
.filter(([_, enabled]) => enabled)
41+
.map(([provider, _]) => provider),
42+
);
4043
}
4144

4245
async status(user: User) {

backend/src/oauth/provider/discord.provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class DiscordProvider implements OAuthProvider<DiscordToken> {
8585
if (limitedUsers) {
8686
await this.checkLimitedUsers(user, limitedUsers);
8787
}
88-
88+
8989
return {
9090
provider: "discord",
9191
providerId: user.id,

frontend/src/services/auth.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const signUp = async (email: string, username: string, password: string) => {
3131
const signOut = async () => {
3232
const response = await api.post("/auth/signOut");
3333

34-
if (URL.canParse(response.data?.redirectURI)) window.location.href = response.data.redirectURI;
34+
if (URL.canParse(response.data?.redirectURI))
35+
window.location.href = response.data.redirectURI;
3536
else window.location.reload();
3637
};
3738

0 commit comments

Comments
 (0)