From 8594b7e8f3058a8d441413a033aee311ee59bdfd Mon Sep 17 00:00:00 2001 From: Melissa Zhang Date: Fri, 10 Jul 2020 16:26:08 -0700 Subject: hypothes.is authentication is fully functional, no longer need to manually input username/api key --- src/server/ApiManagers/HypothesisManager.ts | 4 ++-- src/server/database.ts | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/server') diff --git a/src/server/ApiManagers/HypothesisManager.ts b/src/server/ApiManagers/HypothesisManager.ts index 73c707a55..370d02a49 100644 --- a/src/server/ApiManagers/HypothesisManager.ts +++ b/src/server/ApiManagers/HypothesisManager.ts @@ -14,7 +14,7 @@ export default class HypothesisManager extends ApiManager { subscription: "/readHypothesisAccessToken", secureHandler: async ({ user, res }) => { const credentials = await Database.Auxiliary.HypothesisAccessToken.Fetch(user.id); - res.send(credentials?.hypothesisApiKey ?? ""); + res.send(credentials ? { username: credentials.hypothesisUsername, apiKey: credentials.hypothesisApiKey } : ""); } }); @@ -22,7 +22,7 @@ export default class HypothesisManager extends ApiManager { method: Method.POST, subscription: "/writeHypothesisAccessToken", secureHandler: async ({ user, req, res }) => { - await Database.Auxiliary.HypothesisAccessToken.Write(user.id, req.body.authenticationCode); + await Database.Auxiliary.HypothesisAccessToken.Write(user.id, req.body.authenticationCode, req.body.hypothesisUsername); res.send(); } }); diff --git a/src/server/database.ts b/src/server/database.ts index 767d38350..456c1c254 100644 --- a/src/server/database.ts +++ b/src/server/database.ts @@ -413,6 +413,7 @@ export namespace Database { interface StoredCredentials { userId: string; hypothesisApiKey: string; + hypothesisUsername: string; _id?: string; } @@ -420,8 +421,8 @@ export namespace Database { * Writes the @param hypothesisApiKey to the database, associated * with @param userId for later retrieval and updating. */ - export const Write = async (userId: string, hypothesisApiKey: string) => { - return Instance.insert({ userId, hypothesisApiKey }, AuxiliaryCollections.HypothesisAccess); + export const Write = async (userId: string, hypothesisApiKey: string, hypothesisUsername: string) => { + return Instance.insert({ userId, hypothesisApiKey, hypothesisUsername }, AuxiliaryCollections.HypothesisAccess); }; /** -- cgit v1.2.3-70-g09d2