When an organization is deleted, we need to issue a new pair of oauth tokens and session for the user if the organization is the what they are currently authenticated into (this will always be true when using the UI, a little different when using the CLI or API directly). This PR attempts to solve the first case of using access tokens + sessions.
We also need to update the defaultOrgID in the user settings for future login attempts if the org that was deleted was the defaultOrgID.
Finally, we need to ensure personal orgs cannot be deleted except when the user itself is deleted.
Details
New Tokens
When an org is deleted, a new set of access tokens and refresh tokens are issue and set in the cookie:
Create Org:
(⎈ |default:default)➜ datum git:(feat-delete-org-session) go run cmd/cli/main.go org create -n funkytown4
...
Switch to Org:
(⎈ |default:default)➜ datum git:(feat-delete-org-session) go run cmd/cli/main.go switch -t 01J16WHRTYP2XMHNBC0BERVN32
Successfully switched to organization: 01J16WHRTYP2XMHNBC0BERVN32!
auth tokens successfully stored in keychain
Delete org:
(⎈ |default:default)➜ datum git:(feat-delete-org-session) go run cmd/cli/main.go org delete -i 01J16WHRTYP2XMHNBC0BERVN32
{
"deleteOrganization": {
"deletedID": "01J16WHRTYP2XMHNBC0BERVN32"
}
}
New token's will now get saved and subsequent requests will continue to work:
(⎈ |default:default)➜ datum git:(feat-delete-org-session) go run cmd/cli/main.go org get
ID NAME DESCRIPTION PERSONALORG CHILDREN MEMBERS
01J169Y91PJEXBDGCCNTEFBHDM Organic Katydid Personal Organization - Matt Anderson true 0 1
Default Org Update
Deleted default org should update to another org:
Before deleting org:
(⎈ |default:default)➜ datum git:(feat-delete-org-session) go run cmd/cli/main.go user get -z json |jq -r '.users.edges[0].node.setting.defaultOrg.name'
funkytown4
Delete Org:
(⎈ |default:default)➜ datum git:(feat-delete-org-session) go run cmd/cli/main.go org delete -i 01J16WMYMMM988WTYVTCDCPHEM
{
"deleteOrganization": {
"deletedID": "01J16WMYMMM988WTYVTCDCPHEM"
}
}
After deleting org, the default org is updated:
(⎈ |default:default)➜ datum git:(feat-delete-org-session) go run cmd/cli/main.go user get -z json |jq -r '.users.edges[0].node.setting.defaultOrg.name'
Organic Katydid
Personal Org Deletion
Attempting to delete a personal org results in an error:
(⎈ |default:default)➜ datum git:(feat-delete-org-session) go run cmd/cli/main.go org delete -i 01J169Y91PJEXBDGCCNTEFBHDM
Error: {"networkErrors":null,"graphqlErrors":[{"message":"invalid input: cannot delete personal organizations","path":["deleteOrganization"]}]}
Summary
When an organization is deleted, we need to issue a new pair of oauth tokens and session for the user if the organization is the what they are currently authenticated into (this will always be true when using the UI, a little different when using the CLI or API directly). This PR attempts to solve the first case of using access tokens + sessions.
We also need to update the
defaultOrgID
in the user settings for future login attempts if the org that was deleted was the defaultOrgID.Finally, we need to ensure personal orgs cannot be deleted except when the user itself is deleted.
Details
New Tokens
When an org is deleted, a new set of access tokens and refresh tokens are issue and set in the cookie:
Create Org:
Switch to Org:
Delete org:
New token's will now get saved and subsequent requests will continue to work:
Default Org Update
Deleted default org should update to another org: Before deleting org:
Delete Org:
After deleting org, the default org is updated:
Personal Org Deletion
Attempting to delete a personal org results in an error: