Skip to content

Commit ae2c203

Browse files
committed
createSession() API code refractored.
Signed-off-by: Gaurav Goel <[email protected]>
1 parent 6d40a15 commit ae2c203

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Assets/Plugins/Web3AuthSDK/Web3Auth.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ private void sessionTimeOutAPI()
470470
}
471471

472472
private async Task<string> createSession(string data, long sessionTime) {
473+
TaskCompletionSource<string> createSessionResponse = new TaskCompletionSource<string>();
473474
var newSessionKey = KeyStoreManagerUtils.generateRandomSessionKey();
474475
var ephemKey = KeyStoreManagerUtils.getPubKey(newSessionKey);
475476
var ivKey = KeyStoreManagerUtils.generateRandomBytes();
@@ -506,17 +507,19 @@ private async Task<string> createSession(string data, long sessionTime) {
506507
try
507508
{
508509
this.Enqueue(() => KeyStoreManagerUtils.savePreferenceData(KeyStoreManagerUtils.SESSION_ID, newSessionKey));
510+
createSessionResponse.SetResult(newSessionKey);
509511
}
510512
catch (Exception ex)
511513
{
512-
newSessionKey = null;
514+
createSessionResponse.SetException(new Exception("Something went wrong. Please try again later."));
513515
Debug.LogError(ex.Message);
514516
}
517+
} else {
518+
createSessionResponse.SetException(new Exception("Something went wrong. Please try again later."));
515519
}
516520
}
517521
));
518-
await Task.Delay(200);
519-
return newSessionKey;
522+
return await createSessionResponse.Task;
520523
}
521524

522525
public string getPrivKey()

0 commit comments

Comments
 (0)