Skip to content
Snippets Groups Projects
Unverified Commit d31150ee authored by Kevin Lee's avatar Kevin Lee Committed by GitHub
Browse files

Merge pull request #22 from mozilla/feature/auth_for_allhands

Feature/auth for allhands
parents 1b62f259 b893c998
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ import "./systems/personal-space-bubble"; ...@@ -27,7 +27,7 @@ import "./systems/personal-space-bubble";
import registerNetworkScheams from "./network-schemas"; import registerNetworkScheams from "./network-schemas";
import registerInputMappings from "./input-mappings"; import registerInputMappings from "./input-mappings";
import { promptForName } from "./utils"; import { promptForName, getCookie, parseJwt } from "./utils";
import Config from "./config"; import Config from "./config";
registerNetworkScheams(); registerNetworkScheams();
...@@ -77,10 +77,20 @@ window.App = { ...@@ -77,10 +77,20 @@ window.App = {
playerRig.setAttribute("virtual-gamepad-controls", {}); playerRig.setAttribute("virtual-gamepad-controls", {});
} }
let username = qs.name; let username;
if (!username) { const jwt = getCookie("jwt");
if (jwt) { //grab name from jwt
const data = parseJwt(jwt);
username = data.typ.name;
}
if (qs.name) {
username = qs.name; //always override with name from querystring if available
}
else {
username = promptForName(username); // promptForName is blocking username = promptForName(username); // promptForName is blocking
} }
const myNametag = document.querySelector("#player-rig .nametag"); const myNametag = document.querySelector("#player-rig .nametag");
myNametag.setAttribute("text", "value", username); myNametag.setAttribute("text", "value", username);
......
...@@ -166,10 +166,24 @@ export function generateName() { ...@@ -166,10 +166,24 @@ export function generateName() {
return name.replace(/^./, name[0].toUpperCase()); return name.replace(/^./, name[0].toUpperCase());
} }
export function promptForName() { export function promptForName(username) {
var username = generateName(); if (!username)
username = generateName();
do { do {
username = prompt("Choose a username", username); username = prompt("Choose a username", username);
} while (!(username && username.length)); } while (!(username && username.length));
return username; return username;
} }
export function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
export function parseJwt (token) {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace('-', '+').replace('_', '/');
return JSON.parse(window.atob(base64));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment