11import crypto from "crypto" ;
22import jwt from "jsonwebtoken" ;
3- import type { Errorable } from "socket-call-server" ;
43import { useSocketEvents } from "socket-call-server" ;
54
65import { prismaClient } from "~prisma-schemas/schemas/dm/client" ;
@@ -67,20 +66,20 @@ const listenEvents = () => ({
6766 password : string ;
6867 password2 : string ;
6968 token : string ;
70- } ) : Promise < Errorable < { token : string } , string > > =>
69+ } ) =>
7170 new Promise ( ( resolve ) => {
7271 jwt . verify (
7372 token ,
7473 process . env . TOKEN_SECRET as string ,
7574 async ( err : unknown , data : unknown ) => {
7675 if ( err ) {
77- resolve ( { error : "Invalid token" } ) ;
76+ resolve ( { error : "Invalid token" } as const ) ;
7877 } else if ( password . length < 6 ) {
7978 resolve ( {
8079 error : "Your password should be at least 6 characters long" ,
81- } ) ;
80+ } as const ) ;
8281 } else if ( password !== password2 ) {
83- resolve ( { error : "The two passwords should be identical" } ) ;
82+ resolve ( { error : "The two passwords should be identical" } as const ) ;
8483 } else {
8584 const hashedPassword = crypto
8685 . createHash ( "sha1" )
@@ -100,11 +99,11 @@ const listenEvents = () => ({
10099 } ,
101100 } ) ) ! ;
102101
103- resolve ( { token : await loginAs ( user , hashedPassword ) } ) ;
102+ resolve ( { token : await loginAs ( user , hashedPassword ) } as const ) ;
104103 }
105104 } ,
106105 ) ;
107- resolve ( { error : "Something went wrong" } ) ;
106+ resolve ( { error : "Something went wrong" } as const ) ;
108107 } ) ,
109108
110109 getCsrf : async ( ) => "" ,
@@ -113,7 +112,7 @@ const listenEvents = () => ({
113112 username : string ;
114113 password : string ;
115114 email : string ;
116- } ) : Promise < Errorable < string , "Bad request" > > =>
115+ } ) =>
117116 new Promise ( async ( resolve ) => {
118117 console . log ( `signup with user ${ input . username } ` ) ;
119118 await prismaDm . $transaction ( async ( transaction ) => {
@@ -125,7 +124,7 @@ const listenEvents = () => ({
125124 new PasswordValidation ( ) ,
126125 ] ) ;
127126 if ( scopedError ) {
128- resolve ( { error : "Bad request" , ...scopedError } ) ;
127+ resolve ( { error : "Bad request" , ...scopedError } as const ) ;
129128 } else {
130129 const { username, password, email } = input ;
131130 const hashedPassword = getHashedPassword ( password ) ;
0 commit comments