Socket connection now works
- Pairing a new device works (I did a lot since the last commit)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { hash, verify } from 'argon2';
|
||||
import { verify as jwtVerify } from 'jsonwebtoken';
|
||||
import { config } from '../config';
|
||||
import { IS_DEBUG, logger } from '../app';
|
||||
import { IS_DEBUG, JWT_SECRET, logger } from '../app';
|
||||
|
||||
export async function hashPassword(input: string): Promise<string> {
|
||||
const start = Date.now();
|
||||
@@ -64,9 +65,19 @@ export async function verifyPassword(password: string, hashInput: string): Promi
|
||||
});
|
||||
}
|
||||
|
||||
export function randomString(length: number): string {
|
||||
export async function verifyJWT(token: string): Promise<boolean> {
|
||||
return new Promise<boolean>(async (resolve, reject) => {
|
||||
try {
|
||||
jwtVerify(token, JWT_SECRET, { algorithms: ['HS256'] });
|
||||
resolve(true);
|
||||
} catch {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function randomString(length: number, characters: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'): string {
|
||||
let result = '';
|
||||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
const charactersLength = characters.length;
|
||||
for ( let i = 0; i < length; i++ ) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
|
||||
Reference in New Issue
Block a user