-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
123 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
interface Props { | ||
publicKey: string; | ||
encryptedPrivateKey: string; | ||
iv: string; | ||
tag: string; | ||
privateTag: string; | ||
} | ||
|
||
export const saveTokenToLocalStorage = ({ | ||
publicKey, | ||
encryptedPrivateKey, | ||
iv, | ||
tag, | ||
privateTag, | ||
}: Props) => { | ||
try { | ||
localStorage.setItem("publicKey", publicKey); | ||
localStorage.setItem("encryptedPrivateKey", encryptedPrivateKey); | ||
localStorage.setItem("iv", iv); | ||
localStorage.setItem("tag", tag); | ||
localStorage.setItem("PRIVATE_KEY", privateTag); | ||
} catch (err) { | ||
if (err instanceof Error) { | ||
throw new Error( | ||
"Unable to send the tokens in local storage:" + err.message | ||
); | ||
} | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
interface Login1 { | ||
serverPublicKey: string; | ||
salt: string; | ||
} | ||
|
||
/** | ||
* This is the first step of the login process (pake) | ||
* @param {*} email | ||
* @param {*} clientPublicKey | ||
* @returns | ||
*/ | ||
const login1 = async (email: string, clientPublicKey: string) => { | ||
const response = await fetch("/api/v1/auth/login1", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
email: email, | ||
clientPublicKey, | ||
}), | ||
}); | ||
// need precise error handling about the status code | ||
if (response?.status === 200) { | ||
const data = (await response.json()) as unknown as Login1; | ||
return data; | ||
} | ||
|
||
throw new Error("Wrong password"); | ||
}; | ||
|
||
export default login1; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
interface Login2Response { | ||
encryptedPrivateKey: string; | ||
iv: string; | ||
publicKey: string; | ||
tag: string; | ||
token: string; | ||
} | ||
|
||
/** | ||
* This is the second step of the login process | ||
* @param {*} email | ||
* @param {*} clientPublicKey | ||
* @returns | ||
*/ | ||
const login2 = async (email: string, clientProof: string) => { | ||
const response = await fetch("/api/v1/auth/login2", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
email: email, | ||
clientProof, | ||
}), | ||
credentials: "include", | ||
}); | ||
// need precise error handling about the status code | ||
if (response.status == 200) { | ||
const data = (await response.json()) as unknown as Login2Response; | ||
return data; | ||
} | ||
|
||
throw new Error("Password verification failed"); | ||
}; | ||
|
||
export default login2; |