Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions components/dashboard/src/user-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ const UserContext = createContext<{
setUser: () => null,
});

const refetchCookie = async () => {
await fetch("/api/auth/jwt-cookie", {
credentials: "include",
})
.then((resp) => resp.text())
.then((text) => console.log(`Completed JWT Cookie refresh: ${text}`))
.catch((err) => {
console.log("Failed to update jwt-cookie", err);
});
};

const UserContextProvider: React.FC = ({ children }) => {
const [user, setUser] = useState<User>();

Expand Down Expand Up @@ -46,16 +57,9 @@ const UserContextProvider: React.FC = ({ children }) => {
const frequencyMs = 1000 * 60 * 5; // 5 mins
if (!_gp.jwttimer) {
// Store the timer on the window, to avoid queuing up multiple
_gp.jwtTimer = setInterval(() => {
fetch("/api/auth/jwt-cookie", {
credentials: "include",
})
.then((resp) => resp.text())
.then((text) => console.log(`Completed JWT Cookie refresh: ${text}`))
.catch((err) => {
console.log("Failed to update jwt-cookie", err);
});
}, frequencyMs);
_gp.jwtTimer = setInterval(refetchCookie, frequencyMs);

setTimeout(refetchCookie, 20_000);
}
},
[user, client],
Expand Down
1 change: 1 addition & 0 deletions components/server/src/auth/login-completion-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class LoginCompletionHandler {
// (default case) If we got redirected here onto the base domain of the Gitpod installation, we can just issue the cookie right away.
const cookie = await this.session.createJWTSessionCookie(user.id);
response.cookie(cookie.name, cookie.value, cookie.opts);
this.session.setHashedUserIdCookie(request, response);
reportJWTCookieIssued();

log.info(logContext, `User is logged in successfully. Redirect to: ${returnTo}`);
Expand Down
2 changes: 1 addition & 1 deletion components/server/src/session-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class SessionHandler {
});
}

private setHashedUserIdCookie(req: express.Request, res: express.Response): void {
public setHashedUserIdCookie(req: express.Request, res: express.Response): void {
const user = req.user as User;
if (!user) return;

Expand Down
Loading