Skip to content

Commit 0e5046f

Browse files
author
Itai Levi
authored
[TIC-474] Add get/set functions for Active Org (#18)
* feat(org): add get/set for active org ID * refactor: move tests to dedicated folder * feat(index): export new functions * chore: update dev dependencies * refactor(cookies): create cookie here instead of JS utils * feat(org): add options to cookie
1 parent 316e63a commit 0e5046f

File tree

10 files changed

+97
-8711
lines changed

10 files changed

+97
-8711
lines changed

package-lock.json

Lines changed: 18 additions & 8650 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
"@rollup/plugin-commonjs": "^19.0.0",
2222
"@rollup/plugin-node-resolve": "^13.0.4",
2323
"@types/jest": "^26.0.23",
24+
"@types/js-cookie": "^3.0.6",
2425
"@typescript-eslint/eslint-plugin": "^4.22.0",
2526
"@typescript-eslint/parser": "^4.22.0",
2627
"babel-loader": "^8.2.2",
2728
"jest": "^27.2.4",
29+
"js-cookie": "^3.0.5",
2830
"prettier": "^2.4.1",
2931
"prettier-plugin-organize-imports": "^2.3.3",
3032
"rollup": "^2.46.0",

src/cookies.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const ACTIVE_ORG_ID_COOKIE_NAME = "active_org_id"

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export type { AccessHelper, AccessHelperWithOrg } from "./access_helper"
22
export type { AuthenticationInfo } from "./api"
33
export { createClient } from "./client"
44
export type { IAuthClient, IAuthOptions, RedirectToLoginOptions, RedirectToSignupOptions } from "./client"
5+
export { getActiveOrgId, setActiveOrgId } from "./org"
56
export type { OrgIdToOrgMemberInfo, OrgMemberInfo } from "./org"
67
export type { OrgHelper } from "./org_helper"
78
export { UserClass, UserOrgInfo } from "./user"

src/org.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import Cookies from "js-cookie"
2+
import { ACTIVE_ORG_ID_COOKIE_NAME } from "./cookies"
3+
14
export type OrgMemberInfo = {
25
orgId: string
36
orgName: string
@@ -9,3 +12,14 @@ export type OrgMemberInfo = {
912
export type OrgIdToOrgMemberInfo = {
1013
[orgId: string]: OrgMemberInfo
1114
}
15+
16+
export const setActiveOrgId = (orgId: string) => {
17+
Cookies.set(ACTIVE_ORG_ID_COOKIE_NAME, orgId, {
18+
sameSite: "lax",
19+
secure: true,
20+
})
21+
}
22+
23+
export const getActiveOrgId = (): string | undefined => {
24+
return Cookies.get(ACTIVE_ORG_ID_COOKIE_NAME)
25+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* @jest-environment jsdom
33
*/
4-
import { getAccessHelper } from "./access_helper"
5-
import { createOrgs, createOrgIdToOrgMemberInfo } from "./test_helper"
6-
4+
import { getAccessHelper } from "../access_helper"
5+
import { createOrgIdToOrgMemberInfo, createOrgs } from "./test_helper"
6+
77
it("accessHelper validate methods work", async () => {
88
const orgs = createOrgs(1)
99
const orgId = orgs[0].orgId
Lines changed: 56 additions & 56 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* @jest-environment jsdom
33
*/
44
import { v4 as uuidv4 } from "uuid"
5-
import { getOrgHelper } from "./org_helper"
6-
import { createOrgs, createOrgIdToOrgMemberInfo, getAllProperties } from "./test_helper"
5+
import { getOrgHelper } from "../org_helper"
6+
import { createOrgIdToOrgMemberInfo, createOrgs, getAllProperties } from "./test_helper"
77

88
beforeEach(() => {
99
const localStorageMock = (function () {

0 commit comments

Comments
 (0)