From e2ef8a1a19c7cba827f9034d6b690db2179435a8 Mon Sep 17 00:00:00 2001 From: Jordan Knott Date: Sat, 12 Sep 2020 03:24:09 -0500 Subject: [PATCH] fix: initial access token after install is now set correctly --- frontend/src/Install/index.tsx | 4 ++-- frontend/src/Projects/index.tsx | 2 ++ frontend/src/shared/utils/accessToken.ts | 1 + internal/route/auth.go | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/src/Install/index.tsx b/frontend/src/Install/index.tsx index fd4ac2d..3269ab2 100644 --- a/frontend/src/Install/index.tsx +++ b/frontend/src/Install/index.tsx @@ -59,7 +59,7 @@ const Install = () => { } else { const response: RefreshTokenResponse = await x.data; const { accessToken: newToken, isInstalled } = response; - const claims: JWTToken = jwtDecode(accessToken); + const claims: JWTToken = jwtDecode(newToken); const currentUser = { id: claims.userId, roles: { @@ -69,7 +69,7 @@ const Install = () => { }, }; setUser(currentUser); - setAccessToken(accessToken); + setAccessToken(newToken); if (!isInstalled) { history.replace('/install'); } diff --git a/frontend/src/Projects/index.tsx b/frontend/src/Projects/index.tsx index 3f989b4..c2fe120 100644 --- a/frontend/src/Projects/index.tsx +++ b/frontend/src/Projects/index.tsx @@ -8,6 +8,8 @@ import { useCreateProjectMutation, GetProjectsDocument, GetProjectsQuery, + MeQuery, + MeDocument, } from 'shared/generated/graphql'; import { Link } from 'react-router-dom'; diff --git a/frontend/src/shared/utils/accessToken.ts b/frontend/src/shared/utils/accessToken.ts index f1dc802..739cb12 100644 --- a/frontend/src/shared/utils/accessToken.ts +++ b/frontend/src/shared/utils/accessToken.ts @@ -1,6 +1,7 @@ let accessToken = ''; export function setAccessToken(newToken: string) { + console.log(newToken); accessToken = newToken; } export function getAccessToken() { diff --git a/internal/route/auth.go b/internal/route/auth.go index 46b3455..4b9e73c 100644 --- a/internal/route/auth.go +++ b/internal/route/auth.go @@ -251,10 +251,12 @@ func (h *TaskcafeHandler) InstallHandler(w http.ResponseWriter, r *http.Request) refreshExpiresAt := refreshCreatedAt.AddDate(0, 0, 1) refreshTokenString, err := h.repo.CreateRefreshToken(r.Context(), db.CreateRefreshTokenParams{user.UserID, refreshCreatedAt, refreshExpiresAt}) + log.WithField("userID", user.UserID.String()).Info("creating install access token") accessTokenString, err := auth.NewAccessToken(user.UserID.String(), auth.Unrestricted, user.RoleCode) if err != nil { w.WriteHeader(http.StatusInternalServerError) } + log.Info(accessTokenString) w.Header().Set("Content-type", "application/json") http.SetCookie(w, &http.Cookie{