Skip to content

Commit ab1c405

Browse files
committed
Set tables workspace selection cookie upon user signup/signin
1 parent fbe5a81 commit ab1c405

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

packages/server/api/src/app/authentication/basic/authentication-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const authenticationService = {
5858
projectId: projectContext.project.id,
5959
projectRole: projectContext.projectRole,
6060
tablesRefreshToken: projectContext.tablesRefreshToken,
61+
tablesWorkspaceId: projectContext.project.tablesWorkspaceId,
6162
};
6263
},
6364
};

packages/server/api/src/app/authentication/context/authentication-cookies.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function setAuthCookiesAndReply(
1515
const date = jwtDecode<{ exp: number }>(response.tablesRefreshToken);
1616
const cookieExpiryDate = new Date(date.exp * 1000);
1717

18-
return reply
18+
let replyWithCookies = reply
1919
.setCookie('jwt_token', response.tablesRefreshToken, {
2020
domain: getOpenOpsSubDomain(),
2121
path: '/',
@@ -29,8 +29,23 @@ export function setAuthCookiesAndReply(
2929
httpOnly: false,
3030
expires: cookieExpiryDate,
3131
sameSite: 'lax',
32-
})
33-
.send(response);
32+
});
33+
34+
if (response.tablesWorkspaceId !== undefined) {
35+
replyWithCookies = replyWithCookies.setCookie(
36+
'baserow_group_id',
37+
String(response.tablesWorkspaceId),
38+
{
39+
domain: getOpenOpsSubDomain(),
40+
path: '/',
41+
signed: true,
42+
httpOnly: false,
43+
expires: cookieExpiryDate,
44+
},
45+
);
46+
}
47+
48+
return replyWithCookies.send(response);
3449
}
3550

3651
export function removeAuthCookiesAndReply(reply: FastifyReply): FastifyReply {
@@ -42,6 +57,10 @@ export function removeAuthCookiesAndReply(reply: FastifyReply): FastifyReply {
4257
.clearCookie('token', {
4358
path: '/',
4459
})
60+
.clearCookie('baserow_group_id', {
61+
domain: getOpenOpsSubDomain(),
62+
path: '/',
63+
})
4564
.send('Cookies removed');
4665
}
4766

packages/shared/src/lib/authentication/dto/authentication-response.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export type AuthenticationResponse = UserWithoutPassword & {
88
projectId: string;
99
projectRole: ProjectMemberRole | null;
1010
tablesRefreshToken: string;
11+
tablesWorkspaceId?: number;
1112
};

0 commit comments

Comments
 (0)