From 1a73ed731ea17c46ac7823577143047097927326 Mon Sep 17 00:00:00 2001
From: Melissa Zhang <mzhang19096@gmail.com>
Date: Thu, 9 Jul 2020 00:00:28 -0700
Subject: check for valid API key, then display extracted hypothes.is username

---
 src/client/apis/HypothesisAuthenticationManager.tsx | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

(limited to 'src/client/apis/HypothesisAuthenticationManager.tsx')

diff --git a/src/client/apis/HypothesisAuthenticationManager.tsx b/src/client/apis/HypothesisAuthenticationManager.tsx
index cffb87227..b299f233e 100644
--- a/src/client/apis/HypothesisAuthenticationManager.tsx
+++ b/src/client/apis/HypothesisAuthenticationManager.tsx
@@ -6,6 +6,7 @@ import { Opt } from "../../fields/Doc";
 import { Networking } from "../Network";
 import "./HypothesisAuthenticationManager.scss";
 import { Scripting } from "../util/Scripting";
+import { Hypothesis } from "./hypothesis/HypothesisApiUtils";
 
 const prompt = "Paste authorization code here...";
 
@@ -44,12 +45,13 @@ export default class HypothesisAuthenticationManager extends React.Component<{}>
                 this.disposer = reaction(
                     () => this.authenticationCode,
                     async authenticationCode => {
-                        if (authenticationCode) {
+                        const userProfile = authenticationCode && await Hypothesis.fetchUser(authenticationCode);
+                        if (userProfile && userProfile.userid !== null) {
                             this.disposer?.();
                             Networking.PostToServer("/writeHypothesisAccessToken", { authenticationCode });
                             runInAction(() => {
                                 this.success = true;
-                                this.credentials = response;
+                                this.credentials = Hypothesis.extractUsername(userProfile.userid); // extract username from profile
                             });
                             this.resetState();
                             resolve(authenticationCode);
-- 
cgit v1.2.3-70-g09d2

