Skip to content

Commit

Permalink
chore: set login type to email_passwordless if loginType returned as …
Browse files Browse the repository at this point in the history
…jwt. fix broken social pfps.
  • Loading branch information
chambaz committed Nov 17, 2023
1 parent 2d40007 commit 55a5d49
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions apps/marginfi-v2-ui/src/hooks/useWalletContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ const WalletProvider = ({ children }: { children: React.ReactNode }) => {

if (web3Auth.getUserInfo) {
const userData = await web3Auth.getUserInfo();
setWeb3AuthLoginType(userData.typeOfLogin || "");
setPfp(userData.profileImage || "");
const loginType = userData.typeOfLogin === "jwt" ? "email_passwordless" : userData.typeOfLogin;
setWeb3AuthLoginType(loginType!);

if (userData.profileImage) {
setPfp(userData.profileImage);
}
}

checkPrivateKeyRequested(web3AuthProvider);
Expand Down Expand Up @@ -224,20 +228,20 @@ const WalletProvider = ({ children }: { children: React.ReactNode }) => {
// called when user requests private key
// stores short lived cookie and forces login
const requestPrivateKey = React.useCallback(async () => {
if (!web3AuthLoginType) return;
if (!web3AuthLoginType || !web3Auth) return;
setWeb3AuthPkCookie("mrgnPrivateKeyRequested", true, { expires: new Date(Date.now() + 5 * 60 * 1000) });
await logout();
await web3Auth.logout();
await loginWeb3Auth(web3AuthLoginType);
}, [web3AuthLoginType]);
}, [web3Auth, web3AuthLoginType]);

// if private key requested cookie is found then fetch pk, store in state, and clear cookie
const checkPrivateKeyRequested = React.useCallback(
async (provider: IProvider) => {
if (!web3AuthPkCookie.mrgnPrivateKeyRequested) return;

const privateKeyHexString = await provider.request({
const privateKeyHexString = (await provider.request({
method: "solanaPrivateKey",
}) as string;
})) as string;
const privateKeyBytes = new Uint8Array(privateKeyHexString.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16)));
const privateKeyBase58 = base58.encode(privateKeyBytes);

Expand Down

1 comment on commit 55a5d49

@vercel
Copy link

@vercel vercel bot commented on 55a5d49 Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.