Skip to content

Commit

Permalink
fix: initial access token after install is now set correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanKnott committed Sep 12, 2020
1 parent 61cd376 commit e2ef8a1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions frontend/src/Install/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -69,7 +69,7 @@ const Install = () => {
},
};
setUser(currentUser);
setAccessToken(accessToken);
setAccessToken(newToken);
if (!isInstalled) {
history.replace('/install');
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/Projects/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
useCreateProjectMutation,
GetProjectsDocument,
GetProjectsQuery,
MeQuery,
MeDocument,
} from 'shared/generated/graphql';

import { Link } from 'react-router-dom';
Expand Down
1 change: 1 addition & 0 deletions frontend/src/shared/utils/accessToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let accessToken = '';

export function setAccessToken(newToken: string) {
console.log(newToken);
accessToken = newToken;
}
export function getAccessToken() {
Expand Down
2 changes: 2 additions & 0 deletions internal/route/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit e2ef8a1

Please sign in to comment.