Browse Source

Update auth.js

Fixes #7; Adds placeholder url to indicate the proper format for entering. Adds validation for empty string to doAuth. Tries to upgrade the protocol scheme from http to https when http was entered, tries to prefix https before if the url doesn't start with it.
pull/15/head
Martijn de Boer 4 years ago committed by GitHub
parent
commit
f2a98e9e4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      src/auth.js

23
src/auth.js

@ -32,6 +32,25 @@ module.exports = function Auth({setOauth}) {
}, []);
function doAuth() {
if (typeof instance === "undefined" || instance === null) {
return;
}
let instanceUri = instance.trim();
if (!instanceUri.toLowerCase().startsWith("https://")) {
let inputUri = null;
try {
inputUri = new URL(instanceUri);
inputUri.protocol = "https";
} catch (e) {
inputUri = new URL("https://"+instanceUri);
}
if (inputUri instanceof URL) {
instanceUri = inputUri.toString();
}
}
let oauth = oauthLib({
instance: instance,
client_name: "GoToSocial Admin Panel",
@ -60,9 +79,9 @@ module.exports = function Auth({setOauth}) {
<h1>OAUTH Login:</h1>
<form onSubmit={(e) => e.preventDefault()}>
<label htmlFor="instance">Instance: </label>
<input value={instance} onChange={updateInstance} id="instance"/>
<input value={instance} onChange={updateInstance} id="instance" placeholder="https://gts.instance.xyz"/>
<button onClick={doAuth}>Authenticate</button>
</form>
</section>
);
};
};

Loading…
Cancel
Save