File tree 1 file changed +12
-3
lines changed
packages/app/src/app/race
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({
69
69
70
70
// verify hash:
71
71
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 ( ) ;
73
81
74
82
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 " ) ;
77
85
}
86
+ else console . log ( "Nice" ) ;
78
87
79
88
return await prisma . $transaction ( async ( tx ) => {
80
89
const result = await tx . result . create ( {
You can’t perform that action at this time.
0 commit comments