Skip to content

Commit

Permalink
feat: improve sample Parcel logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pamapa committed Dec 15, 2021
1 parent 2a6f632 commit 2e1db1a
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 76 deletions.
15 changes: 2 additions & 13 deletions samples/Parcel/src/code-flow-identityserver/sample-callback.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import { Log, UserManager, settings } from "./sample-settings";
import { log } from "./sample";

Log.logger = console;
Log.level = Log.DEBUG;

function log() {
document.getElementById("out").innerText = "";

Array.prototype.forEach.call(arguments, function(msg) {
if (msg instanceof Error) {
msg = "Error: " + msg.message;
}
else if (typeof msg !== "string") {
msg = JSON.stringify(msg, null, 2);
}
document.getElementById("out").innerHTML += msg + "\r\n";
});
}
new UserManager(settings).signinCallback().then(function(user) {
log("signin response success", user);
}).catch(function(err) {
console.error(err);
log(err);
});
17 changes: 6 additions & 11 deletions samples/Parcel/src/code-flow-identityserver/sample-popup-signin.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { Log, UserManager, settings } from "./sample-settings";

var log = {
debug:logMessage, warn: logMessage, info: logMessage, error:logMessage
};

function logMessage(msg) {
document.getElementById("logMessages").innerHTML += "<li>" + msg + "</li>";
console.log(msg);
}
import { log } from "./sample";

Log.logger = console; // log;
Log.level = Log.DEBUG;

new UserManager(settings).signinCallback().catch(function(err) {
Log.logger.error("error: " + err && err.message);
new UserManager(settings).signinCallback().then(function(user) {
log("signin response success", user);
}).catch(function(err) {
console.error(err);
log(err);
});
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { Log, UserManager, settings } from "./sample-settings";
import { log } from "./sample";

Log.logger = console;
Log.level = Log.INFO;

function log() {
document.getElementById("out").innerText = "";

Array.prototype.forEach.call(arguments, function(msg) {
if (msg instanceof Error) {
msg = "Error: " + msg.message;
}
else if (typeof msg !== "string") {
msg = JSON.stringify(msg, null, 2);
}
document.getElementById("out").innerHTML += msg + "\r\n";
});
}
// can pass true param and will keep popup window open
new UserManager(settings).signoutCallback();
new UserManager(settings).signoutCallback().then(function() {
log("signout callback response success");
}).catch(function(err) {
console.error(err);
log(err);
});
21 changes: 7 additions & 14 deletions samples/Parcel/src/code-flow-identityserver/sample-silent.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import { Log, UserManager, settings } from "./sample-settings";
import { log } from "./sample";

Log.logger = console;
Log.level = Log.INFO;

function log() {
document.getElementById("out").innerText = "";

Array.prototype.forEach.call(arguments, function(msg) {
if (msg instanceof Error) {
msg = "Error: " + msg.message;
}
else if (typeof msg !== "string") {
msg = JSON.stringify(msg, null, 2);
}
document.getElementById("out").innerHTML += msg + "\r\n";
});
}
void new UserManager(settings).signinCallback();
new UserManager(settings).signinCallback().then(function(user) {
log("signin callback response success", user);
}).catch(function(err) {
console.error(err);
log(err);
});
22 changes: 19 additions & 3 deletions samples/Parcel/src/code-flow-identityserver/sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,17 @@ mgr.events.addUserSignedOut(function (e) {
function clearState() {
mgr.clearStaleState().then(function() {
log("clearStateState success");
}).catch(function(e) {
log("clearStateState error", e.message);
}).catch(function(err) {
console.error(err);
log(err);
});
}

function getUser() {
mgr.getUser().then(function(user) {
log("got user", user);
}).catch(function(err) {
console.error(err);
log(err);
});
}
Expand All @@ -111,6 +113,7 @@ function removeUser() {
mgr.removeUser().then(function() {
log("user removed");
}).catch(function(err) {
console.error(err);
log(err);
});
}
Expand All @@ -119,6 +122,7 @@ function querySessionStatus() {
mgr.querySessionStatus().then(function(status) {
log("user's session status", status);
}).catch(function(err) {
console.error(err);
log(err);
});
}
Expand All @@ -127,6 +131,7 @@ function revokeAccessToken() {
mgr.revokeAccessToken().then(function() {
log("access token revoked");
}).catch(function(err) {
console.error(err);
log(err);
});
}
Expand All @@ -135,6 +140,7 @@ function startSigninMainWindow() {
mgr.signinRedirect(/*{useReplaceToNavigate:true}*/).then(function() {
log("signinRedirect done");
}).catch(function(err) {
console.error(err);
log(err);
});
}
Expand All @@ -147,6 +153,7 @@ function endSigninMainWindow() {
var theMessage = theState.message;
console.log("here's our post-login state", theMessage);
}).catch(function(err) {
console.error(err);
log(err);
});
}
Expand All @@ -155,6 +162,7 @@ function popupSignin() {
mgr.signinPopup().then(function(user) {
log("signed in", user);
}).catch(function(err) {
console.error(err);
log(err);
});
}
Expand All @@ -163,14 +171,16 @@ function popupSignout() {
mgr.signoutPopup().then(function() {
log("signed out");
}).catch(function(err) {
console.error(err);
log(err);
});
}

function iframeSignin() {
mgr.signinSilent().then(function(user) {
log("signed in", user);
log("signed in silent", user);
}).catch(function(err) {
console.error(err);
log(err);
});
}
Expand All @@ -179,6 +189,7 @@ function startSignoutMainWindow() {
mgr.signoutRedirect().then(function(resp) {
log("signed out", resp);
}).catch(function(err) {
console.error(err);
log(err);
});
}
Expand All @@ -187,6 +198,11 @@ function endSignoutMainWindow() {
mgr.signoutCallback().then(function(resp) {
log("signed out", resp);
}).catch(function(err) {
console.error(err);
log(err);
});
}

export {
log
};
15 changes: 2 additions & 13 deletions samples/Parcel/src/oidc-client/sample-callback.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import { Log, settings } from "./sample-settings";
import { log } from "./sample";

Log.logger = console;
Log.level = Log.INFO;

function log() {
document.getElementById("out").innerText = "";

Array.prototype.forEach.call(arguments, function(msg) {
if (msg instanceof Error) {
msg = "Error: " + msg.message;
}
else if (typeof msg !== "string") {
msg = JSON.stringify(msg, null, 2);
}
document.getElementById("out").innerHTML += msg + "\r\n";
});
}
new OidcClient(settings).processSigninResponse().then(function(response) {
log("signin response success", response);
}).catch(function(err) {
console.error(err);
log(err);
});
7 changes: 7 additions & 0 deletions samples/Parcel/src/oidc-client/sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function signin() {
window.location = req.url;
}
}).catch(function(err) {
console.error(err);
log(err);
});
}
Expand All @@ -54,6 +55,7 @@ function processSigninResponse() {
signinResponse = response;
log("signin response", signinResponse);
}).catch(function(err) {
console.error(err);
log(err);
});
}
Expand All @@ -72,6 +74,7 @@ function processSignoutResponse() {
signinResponse = null;
log("signout response", response);
}).catch(function(err) {
console.error(err);
log(err);
});
}
Expand Down Expand Up @@ -104,3 +107,7 @@ if (followLinks()) {
processSignoutResponse();
}
}

export {
log
};
2 changes: 2 additions & 0 deletions samples/Parcel/src/user-manager/sample-callback.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { UserManager, settings } from "./sample-settings";
import { log } from "./sample";

new UserManager(settings).signinRedirectCallback().then(function(user) {
console.log("signin response success", user);
}).catch(function(err) {
log(err);
console.log(err);
});
13 changes: 11 additions & 2 deletions samples/Parcel/src/user-manager/sample-popup-signin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { UserManager, settings } from "./sample-settings";
import { Log, UserManager, settings } from "./sample-settings";
import { log } from "./sample";

void new UserManager(settings).signinPopupCallback();
Log.logger = console;
Log.level = Log.INFO;

new UserManager(settings).signinPopupCallback().then(function() {
log("signin popup callback response success");
}).catch(function(err) {
console.error(err);
log(err);
});
13 changes: 11 additions & 2 deletions samples/Parcel/src/user-manager/sample-popup-signout.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { UserManager, settings } from "./sample-settings";
import { Log, UserManager, settings } from "./sample-settings";
import { log } from "./sample";

void new UserManager(settings).signoutPopupCallback(undefined, true);
Log.logger = console;
Log.level = Log.INFO;

new UserManager(settings).signoutPopupCallback(undefined, true).then(function() {
log("signout popup callback response success");
}).catch(function(err) {
console.error(err);
log(err);
});
13 changes: 11 additions & 2 deletions samples/Parcel/src/user-manager/sample-silent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { UserManager, settings } from "./sample-settings";
import { Log, UserManager, settings } from "./sample-settings";
import { log } from "./sample";

void new UserManager(settings).signinSilentCallback();
Log.logger = console;
Log.level = Log.INFO;

new UserManager(settings).signinSilentCallback().then(function() {
log("signin silent callback response success");
}).catch(function(err) {
console.error(err);
log(err);
});
Loading

0 comments on commit 2e1db1a

Please sign in to comment.