-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): tenant owner can sign in to its tenant app
- Loading branch information
1 parent
431e4c5
commit 14158d1
Showing
2 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/multi-tenant/src/supertokens/utils/isTenantOwnerEmail.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { UserService } from "@dzangolab/fastify-user"; | ||
import humps from "humps"; | ||
|
||
import getMultiTenantConfig from "../../lib/getMultiTenantConfig"; | ||
|
||
import type { Tenant } from "../../types/tenant"; | ||
import type { ApiConfig } from "@dzangolab/fastify-config"; | ||
import type { Database } from "@dzangolab/fastify-slonik"; | ||
import type { | ||
User, | ||
UserCreateInput, | ||
UserUpdateInput, | ||
} from "@dzangolab/fastify-user"; | ||
import type { QueryResultRow } from "slonik"; | ||
|
||
const isTenantOwnerEmail = async ( | ||
config: ApiConfig, | ||
database: Database, | ||
email: string, | ||
tenant: Tenant | ||
) => { | ||
const userService = new UserService< | ||
User & QueryResultRow, | ||
UserCreateInput, | ||
UserUpdateInput | ||
>(config, database); | ||
|
||
const multiTenantConfig = getMultiTenantConfig(config); | ||
|
||
const owner = await userService.findById( | ||
tenant[humps.camelize(multiTenantConfig.table.columns.ownerId)] | ||
); | ||
|
||
if (owner) { | ||
return email === owner.email; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
export default isTenantOwnerEmail; |