fix: initial access token after install is now set correctly

This commit is contained in:
Jordan Knott 2020-09-12 03:24:09 -05:00
parent 61cd376bfd
commit e2ef8a1a19
4 changed files with 7 additions and 2 deletions

View File

@ -59,7 +59,7 @@ const Install = () => {
} else { } else {
const response: RefreshTokenResponse = await x.data; const response: RefreshTokenResponse = await x.data;
const { accessToken: newToken, isInstalled } = response; const { accessToken: newToken, isInstalled } = response;
const claims: JWTToken = jwtDecode(accessToken); const claims: JWTToken = jwtDecode(newToken);
const currentUser = { const currentUser = {
id: claims.userId, id: claims.userId,
roles: { roles: {
@ -69,7 +69,7 @@ const Install = () => {
}, },
}; };
setUser(currentUser); setUser(currentUser);
setAccessToken(accessToken); setAccessToken(newToken);
if (!isInstalled) { if (!isInstalled) {
history.replace('/install'); history.replace('/install');
} }

View File

@ -8,6 +8,8 @@ import {
useCreateProjectMutation, useCreateProjectMutation,
GetProjectsDocument, GetProjectsDocument,
GetProjectsQuery, GetProjectsQuery,
MeQuery,
MeDocument,
} from 'shared/generated/graphql'; } from 'shared/generated/graphql';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';

View File

@ -1,6 +1,7 @@
let accessToken = ''; let accessToken = '';
export function setAccessToken(newToken: string) { export function setAccessToken(newToken: string) {
console.log(newToken);
accessToken = newToken; accessToken = newToken;
} }
export function getAccessToken() { export function getAccessToken() {

View File

@ -251,10 +251,12 @@ func (h *TaskcafeHandler) InstallHandler(w http.ResponseWriter, r *http.Request)
refreshExpiresAt := refreshCreatedAt.AddDate(0, 0, 1) refreshExpiresAt := refreshCreatedAt.AddDate(0, 0, 1)
refreshTokenString, err := h.repo.CreateRefreshToken(r.Context(), db.CreateRefreshTokenParams{user.UserID, refreshCreatedAt, refreshExpiresAt}) 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) accessTokenString, err := auth.NewAccessToken(user.UserID.String(), auth.Unrestricted, user.RoleCode)
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
} }
log.Info(accessTokenString)
w.Header().Set("Content-type", "application/json") w.Header().Set("Content-type", "application/json")
http.SetCookie(w, &http.Cookie{ http.SetCookie(w, &http.Cookie{