Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanbataire committed Feb 20, 2025
1 parent abbd43f commit 03a913e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/lib/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class Auth {
return new Date(new Date().getTime() + LOGIN_EXPIRES_AFTER_MS);
}


private static encodeToken(session: ChtSession, signingKey: string, expiresIn: string) {
const data = JSON.stringify(session);
return jwt.sign({ data }, signingKey, { expiresIn });
Expand All @@ -59,15 +59,15 @@ export default class Auth {
return ChtSession.createFromDataString(data);
}

public static async apiAuth (username: string, password: string, domain: string) {
public static async apiAuth(username: string, password: string, domain: string) {
const authInfo = await Config.getAuthenticationInfo(domain);
try {
const chtSession = await ChtSession.create(authInfo, username, password);
return chtSession;
} catch (e: any) {
console.error(`Login error: ${e}`);
return {};
}
try {
const chtSession = await ChtSession.create(authInfo, username, password);
return chtSession;
} catch (error: any) {
console.error(`Login error: ${error}`);
return {};
}
}

}
3 changes: 1 addition & 2 deletions src/routes/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { FastifyInstance } from 'fastify';

import Auth from '../lib/authentication';
import { ChtApi } from '../lib/cht-api';
import { Config, ConfigSystem } from '../config';
import { Config } from '../config';
import DirectiveModel from '../services/directive-model';
import RemotePlaceCache from '../lib/remote-place-cache';
import RemotePlaceResolver from '../lib/remote-place-resolver';
import SessionCache from '../services/session-cache';
import { UploadManager } from '../services/upload-manager';
import WarningSystem from '../warnings';
import { writeConfig } from '../config/config-factory';

export default async function sessionCache(fastify: FastifyInstance) {
fastify.get('/', async (req, resp) => {
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const build = (opts: FastifyServerOptions): FastifyInstance => {

const { isAdmin }: any = await Auth.apiAuth(username, password, domain);

if (isAdmin) {
if (isAdmin === true) {
return;
}
reply.status(401).send({ error: 'unauthorized' });
Expand Down

0 comments on commit 03a913e

Please sign in to comment.