Skip to content

Commit cb2f576

Browse files
committed
chore: signout working
1 parent 1200e31 commit cb2f576

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

src/nls/root/strings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,10 +1569,13 @@ define({
15691569
// login
15701570
"SIGNED_OUT": "You have been signed out.",
15711571
"SIGNED_OUT_MESSAGE": "You have been signed out of your {APP_NAME} account. Please sign in again to continue.",
1572+
"SIGNED_OUT_MESSAGE_FRIENDLY": "Thank you for using {APP_NAME}. See you soon!",
15721573
"SIGNED_IN_OFFLINE_TITLE": "Offline - Cannot Sign In",
15731574
"SIGNED_IN_OFFLINE_MESSAGE": "Please connect to the internet to sign in to {APP_NAME}.",
15741575
"SIGNED_IN_FAILED_TITLE": "Cannot Sign In",
15751576
"SIGNED_IN_FAILED_MESSAGE": "Something went wrong while trying to sign in. Please try again.",
1577+
"SIGNED_OUT_FAILED_TITLE": "Failed to Sign Out",
1578+
"SIGNED_OUT_FAILED_MESSAGE": "Something went wrong while trying to sign out. Please try again.",
15761579
"VALIDATION_CODE_TITLE": "Sign In Verification Code",
15771580
"VALIDATION_CODE_MESSAGE": "Please use this Verification code to sign in to your {APP_NAME} account:",
15781581
"COPY_VALIDATION_CODE": "Copy Code",

src/services/login.js

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ define(function (require, exports, module) {
9494
}
9595
}
9696

97+
async function _resetAccountLogin() {
98+
isLoggedInUser = false;
99+
ProfileMenu.setNotLoggedIn();
100+
await KernalModeTrust.removeCredential(KernalModeTrust.CRED_KEY_API);
101+
}
102+
97103
async function _verifyLogin() {
98104
const savedUserProfile = await KernalModeTrust.getCredential(KernalModeTrust.CRED_KEY_API);
99105
if(!savedUserProfile){
@@ -122,14 +128,13 @@ define(function (require, exports, module) {
122128
}
123129
// some error happened.
124130
if(resolveResponse.err === ERR_INVALID) { // the api key is invalid, we need to logout and tell user
125-
isLoggedInUser = false;
126-
ProfileMenu.setNotLoggedIn();
131+
_resetAccountLogin()
132+
.catch(console.error);
127133
Dialogs.showModalDialog(
128134
DefaultDialogs.DIALOG_ID_ERROR,
129135
Strings.SIGNED_OUT,
130136
Strings.SIGNED_OUT_MESSAGE
131137
);
132-
await KernalModeTrust.removeCredential(KernalModeTrust.CRED_KEY_API);
133138
}
134139
// maybe some intermittent network error, ERR_RETRY_LATER is here. do nothing
135140
}
@@ -253,6 +258,50 @@ define(function (require, exports, module) {
253258
NativeApp.openURLInDefaultBrowser(appSignInURL);
254259
}
255260

261+
async function signOutAccount() {
262+
try {
263+
const resolveURL = `${Phoenix.config.account_url}logoutSession`;
264+
let input = {
265+
appSessionID: userProfile.apiKey
266+
};
267+
268+
const response = await fetch(resolveURL, {
269+
method: 'POST',
270+
headers: {
271+
'Content-Type': 'application/json'
272+
},
273+
body: JSON.stringify(input)
274+
});
275+
276+
const result = await response.json();
277+
278+
if (!result.isSuccess) {
279+
console.error('Error logging out', result);
280+
Dialogs.showModalDialog(
281+
DefaultDialogs.DIALOG_ID_ERROR,
282+
Strings.SIGNED_OUT_FAILED_TITLE,
283+
Strings.SIGNED_OUT_FAILED_MESSAGE
284+
);
285+
return;
286+
// todo raise metrics
287+
}
288+
await _resetAccountLogin();
289+
Dialogs.showModalDialog(
290+
DefaultDialogs.DIALOG_ID_INFO,
291+
Strings.SIGNED_OUT,
292+
Strings.SIGNED_OUT_MESSAGE_FRIENDLY
293+
);
294+
} catch (error) {
295+
console.error("Network error. Could not log out session.", error);
296+
Dialogs.showModalDialog(
297+
DefaultDialogs.DIALOG_ID_ERROR,
298+
Strings.SIGNED_OUT_FAILED_TITLE,
299+
Strings.SIGNED_OUT_FAILED_MESSAGE
300+
);
301+
// todo raise metrics
302+
}
303+
}
304+
256305
function init() {
257306
ProfileMenu.init();
258307
if(!Phoenix.isNativeApp){
@@ -273,6 +322,7 @@ define(function (require, exports, module) {
273322
// kernal exports
274323
secureExports.isLoggedIn = isLoggedIn;
275324
secureExports.signInToAccount = signInToAccount;
325+
secureExports.signOutAccount = signOutAccount;
276326

277327
// public exports
278328
exports.isLoggedIn = isLoggedIn;

src/services/profile-menu.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,13 @@ define(function (require, exports, module) {
6262
};
6363

6464
function _handleSignInBtnClick() {
65-
console.log("User clicked sign in button");
6665
closePopup(); // need to close the current popup to show the new one
6766
KernalModeTrust.loginService.signInToAccount();
6867
}
6968

7069
function _handleSignOutBtnClick() {
71-
console.log("User clicked sign out");
7270
closePopup();
73-
showLoginPopup();
71+
KernalModeTrust.loginService.signOutAccount();
7472
}
7573

7674
function _handleContactSupportBtnClick() {

0 commit comments

Comments
 (0)