Last active
October 25, 2020 16:34
-
-
Save SilentImp/7555e60daa4b13d830259a8622c8ecf5 to your computer and use it in GitHub Desktop.
Experiment with setLoggedIn API. Should work in Safari.
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>isLoggedIn API</title> | |
</head> | |
<body> | |
<header> | |
<button id="signin" type="button">Sign-in</button> | |
<button id="signout" type="button">Sign-out</button> | |
</header> | |
<main> | |
User is <output id="output"></output> | |
</main> | |
<script> | |
(async () => { | |
if (!navigator.isLoggedIn) return; | |
const signIn = document.getElementById('signin'); | |
const signOut = document.getElementById('signout'); | |
const output = document.getElementById('output'); | |
const checkIsLoggedIn = async () => { | |
const isLoggedIn = await navigator.isLoggedIn(); // It looks like always resolved with `true`. | |
console.log('isLoggedIn: ', isLoggedIn); | |
output.innerText = isLoggedIn ? 'authenticated' : 'anonimus'; | |
} | |
signIn.addEventListener('click', async (event) => { | |
try { | |
console.log(navigator.setLoggedIn); | |
const response1 = await navigator.setLoggedIn({ | |
username: "silentimp", | |
credentialTokenType: "legacyAuthCookie" | |
}); // resolved with `undefined`. | |
console.log(response1); | |
const response2 = await navigator.setLoggedIn("silentimp", "legacyAuthCookie"); // resolved with `undefined`. | |
console.log(response2); | |
checkIsLoggedIn(); | |
} catch (error) { | |
console.log(error); | |
} | |
}); | |
signOut.addEventListener('click', async (event) => { | |
const response = await navigator.setLoggedOut("silentimp"); // resolved with `undefined`. | |
console.log(response); | |
checkIsLoggedIn(); | |
}); | |
checkIsLoggedIn(); | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment