Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Mysky autologin stored settings and logout #188

Merged
merged 36 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7d2fe37
Implement logout and setup auto re-login
mrcnski Dec 9, 2021
6a03865
Fix up loose ends for logout and auto re-login
mrcnski Dec 9, 2021
3ef9ad7
Polyfill Promise.any for Opera
mrcnski Dec 15, 2021
5e60df4
Implement getting preferred portal and redirect flow
mrcnski Dec 15, 2021
6d10fe5
Implement preferred portal flow, move portal login to Main MySky
mrcnski Dec 22, 2021
a56b4fe
Fix a couple of lint warnings
mrcnski Dec 22, 2021
3db1e6a
Merge branch 'main' into mysky-autologin-stored-settings-and-logout
mrcnski Dec 22, 2021
c1a7812
Signal to MySky UI that we are done logging in
mrcnski Jan 7, 2022
a8e518d
Refactor MySky get/setJSON based on GSJ rework
mrcnski Jan 7, 2022
181fd70
Address lint errors
mrcnski Jan 7, 2022
eae675b
Fix compilation issues
mrcnski Jan 12, 2022
10a9209
Update tests to use siasky.net, remove references to SKYNET-TOKEN
mrcnski Jan 12, 2022
3d3ce52
Address review comments
mrcnski Jan 13, 2022
cce3dbb
Merge branch 'main' into mysky-autologin-stored-settings-and-logout
mrcnski Jan 13, 2022
6a19718
Fix build errors
mrcnski Jan 14, 2022
bc5065a
Add some fixes, debug lines, and refactors
mrcnski Jan 17, 2022
d922f2d
Fix some bugs, add debug lines, send URL parameters to UI screens
mrcnski Jan 18, 2022
1815b87
Fix some bugs
mrcnski Jan 20, 2022
ccbf35f
Refactor, get user settings in scripts/ui.ts
mrcnski Jan 20, 2022
4034089
Expose functions to allow skynet-js to auto-relogin
mrcnski Jan 21, 2022
a45f435
Fix domain extraction bugs (also fixing user settings bug)
mrcnski Jan 28, 2022
50be38e
Fix bug in `getJSONEncryptedInternal`
mrcnski Jan 31, 2022
4e10f5c
Fix referrer bug
mrcnski Feb 1, 2022
fe13a7b
Fix integration tests
mrcnski Feb 2, 2022
d5b79d1
Don't make MySky initialization fail if the email is invalid
mrcnski Feb 2, 2022
1b44334
Couple of critical fixes
mrcnski Feb 4, 2022
21a0e4b
Merge branch 'main' into mysky-autologin-stored-settings-and-logout
mrcnski Feb 4, 2022
61602fb
Merge branch 'main' into mysky-autologin-stored-settings-and-logout
ro-tex Feb 7, 2022
49eebcc
Fix unexpected request with seed
mrcnski Feb 7, 2022
5b2f738
Merge remote-tracking branch 'origin/mysky-autologin-stored-settings-…
mrcnski Feb 7, 2022
7a76de1
Merge branch 'main' into mysky-autologin-stored-settings-and-logout
mrcnski Feb 8, 2022
307b83a
Fix lint warnings
mrcnski Feb 8, 2022
58d6196
Address most review comments
mrcnski Feb 11, 2022
f9d0b59
Comment `resolveOnMySkyPortalLogin` and unregister event listener
mrcnski Feb 11, 2022
f441ee5
Add explanatory comments
mrcnski Feb 14, 2022
c951e5c
Merge branch 'main' into mysky-autologin-stored-settings-and-logout
ro-tex Feb 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions html/seed-display.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h2 class="mt-6 text-center text-3xl font-extrabold text-gray-900">
<!-- Signup form -->
<div class="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10">
<form class="space-y-6" action="#" onsubmit="window.signUp()">
<form class="space-y-6" action="#" onsubmit="window.signUp(event)">

Choose a reason for hiding this comment

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

nit I think usually you want to call prevent default on the event, but you also want to return false here. I don't know why though unfortunately, I just know onsubmit="whatever(); return false" or onsubmit="return myValidator()" is a thing. Decided to leave the comment since it might be useful to you but feel free to just resolve if we don't care.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds familiar to me, though I unfortunately don't understand what that does either. However,

  1. I know that everything works the way it is now,
  2. I would have to do all the deploys and testing again after making this change, and this was pretty annoying to test.

To me it makes sense to move this to a followup. Maybe at some point I can do a blitz through Issues with Karol or Farzad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

<!-- Passphrase container -->
<div>
<!-- Passphrase label -->
Expand Down Expand Up @@ -231,7 +231,7 @@ <h2 class="mt-6 text-center text-3xl font-extrabold text-gray-900">
}

function showPassword() {
if (seedInput.type === "password") {
if (uiSigninPassphraseText.type === "password") {
uiSigninPassphraseText.type = "text";
uiShowSeedText.textContent = "Hide passphrase";
uiShowSeedOn.classList.add("hidden");
Expand All @@ -245,7 +245,7 @@ <h2 class="mt-6 text-center text-3xl font-extrabold text-gray-900">
}

function confirmStoredPassphrase() {
if (seedConfirm.checked) {
if (uiSeedConfirm.checked) {
uiSignupSubmit.removeAttribute("disabled")
} else {
uiSignupSubmit.setAttribute("disabled", "disabled")
Expand Down
4 changes: 3 additions & 1 deletion html/signin-connect.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h2 class="mt-6 text-center text-3xl font-extrabold text-gray-900">
<div class="relative flex justify-center text-sm">
<span class="px-2 bg-white">
<a href="#" class="text-primary inline-flex items-center" onclick="window.continue()">
<span class="ml-1">not now</span>
<span id="connect-not-now" class="ml-1">not now</span>
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="currentColor" class="bi bi-arrow-right-short" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"/>
</svg>
Expand All @@ -65,5 +65,7 @@ <h2 class="mt-6 text-center text-3xl font-extrabold text-gray-900">
</div>
</div>
</div>

<script async src="signin-connect.js"></script>
</body>
</html>
112 changes: 27 additions & 85 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@
"dependencies": {
"buffer": "^6.0.3",
"confusables": "^1.1.0",
"core-js": "^3.20.2",
"crypto-browserify": "^3.12.0",
"idb-keyval": "^6.1.0",
"mustache": "^4.2.0",
"post-me": "^0.4.5",
"punycode": "^2.1.1",
"randombytes": "^2.1.0",
"skynet-js": "^4.0.21-beta",
"skynet-js": "^4.0.22-beta",
Copy link
Contributor

@ro-tex ro-tex Feb 7, 2022

Choose a reason for hiding this comment

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

We should update this to the latest version and proactively deal with any breaking changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't matter for now because I've linked to a specific branch in skynet-js locally. Changing this line wouldn't affect anything, I just have to keep the skynet-js branch up-to-date with recent changes. I will change this line once the skynet-js branch has been merged and a version change published.

"skynet-mysky-utils": "^0.3.0",
"stream-browserify": "^3.0.0",
"tweetnacl": "^1.0.3",
Expand Down
2 changes: 1 addition & 1 deletion scripts/permissions-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let parentConnection: Connection | null = null;
// ======

window.onerror = function (error: any) {
console.log(error);
console.warn(error);
if (parentConnection) {
if (typeof error === "string") {
void parentConnection.remoteHandle().call("catchError", error);
Expand Down
2 changes: 1 addition & 1 deletion scripts/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const methods = {
// ======

self.onerror = function (error: any) {
console.log(error);
console.warn(error);
if (parentConnection) {
if (typeof error === "string") {
void parentConnection.remoteHandle().call("catchError", error);
Expand Down
8 changes: 6 additions & 2 deletions scripts/seed-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let parentConnection: Connection | null = null;
// ======

window.onerror = function (error: any) {
console.log(error);
console.warn(error);
if (parentConnection) {
if (typeof error === "string") {
void parentConnection.remoteHandle().call("catchError", error);
Expand Down Expand Up @@ -71,6 +71,7 @@ window.onload = async () => {
};

(window as any).signIn = (event: Event) => {
// Prevent making unnecessary request.
event.preventDefault();

const phraseValue = uiSigninPassphraseText.value;
Expand All @@ -86,7 +87,10 @@ window.onload = async () => {
handleResponse({ seed, email: null, action: "signin" });
};

(window as any).signUp = () => {
(window as any).signUp = (event: Event) => {
// Prevent making unnecessary request.
event.preventDefault();

if (uiSeedConfirm.checked === false) return;

const seed = phraseToSeed(uiSignupPassphraseText.value);
Expand Down
2 changes: 1 addition & 1 deletion scripts/seed-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let parentConnection: Connection | null = null;
// ======

window.onerror = function (error: any) {
console.log(error);
console.warn(error);
if (parentConnection) {
if (typeof error === "string") {
void parentConnection.remoteHandle().call("catchError", error);
Expand Down
14 changes: 10 additions & 4 deletions scripts/signin-connect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ChildHandshake, Connection, WindowMessenger } from "post-me";

import { log } from "../src/util";

const uiConnectEmailText = <HTMLInputElement>document.getElementById("connect-email-text")!;

let readyEmail: string | null = null;
Expand All @@ -11,7 +13,7 @@ let parentConnection: Connection | null = null;
// ======

window.onerror = function (error: any) {
console.log(error);
console.warn(error);
if (parentConnection) {
if (typeof error === "string") {
void parentConnection.remoteHandle().call("catchError", error);
Expand All @@ -37,7 +39,7 @@ window.onload = async () => {
};

(window as any).continue = () => {
handleEmail(null);
handleEmail("");
};

// ==========
Expand All @@ -48,6 +50,8 @@ window.onload = async () => {
* Initialize the communication with the UI.
*/
async function init(): Promise<void> {
log("Entered init");

// Establish handshake with parent window.

const messenger = new WindowMessenger({
Expand All @@ -67,11 +71,13 @@ async function init(): Promise<void> {
* @returns - The email, if set.
*/
async function getEmail(): Promise<string | null> {
log("Entered getEmail");

const checkInterval = 100;

return new Promise((resolve) => {
const checkFunc = () => {
if (readyEmail) {
if (readyEmail !== null) {
resolve(readyEmail);
}
};
Expand All @@ -85,7 +91,7 @@ async function getEmail(): Promise<string | null> {
*
* @param email - The email.
*/
function handleEmail(email: string | null): void {
function handleEmail(email: string): void {
// Set `readyEmail`, triggering `getEmail`.
readyEmail = email;
}
Loading