File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
packages/app/src/app/race Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -69,12 +69,21 @@ export const saveUserResultAction = validatedCallback({
6969
7070 // verify hash:
7171 const uniqueKey = 'your-unique-key' ;
72- const hashedData = CryptoJS . HmacSHA256 ( input . data , uniqueKey ) . toString ( ) ;
72+ const data = {
73+ timeTaken : input . timeTaken ,
74+ errors : input . errors ,
75+ cpm : input . cpm ,
76+ accuracy : input . accuracy ,
77+ snippetId : input . snippetId ,
78+ } ;
79+ const jsonData = JSON . stringify ( data ) ;
80+ const hashedData = CryptoJS . HmacSHA256 ( jsonData , uniqueKey ) . toString ( ) ;
7381
7482 if ( hashedData != input . hash . toString ( ) ) {
75- console . log ( input . hash . toString ( ) , hashedData ) ;
76- throw new Error ( "Invalid Request: Data tampered " ) ;
83+ console . log ( jsonData , input . hash . toString ( ) , hashedData ) ;
84+ throw new Error ( "Invalid Request: Tampered Data " ) ;
7785 }
86+ else console . log ( "Nice" ) ;
7887
7988 return await prisma . $transaction ( async ( tx ) => {
8089 const result = await tx . result . create ( {
You can’t perform that action at this time.
0 commit comments