-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(JWT): Generate tenant claims and validate them.
- Loading branch information
Showing
9 changed files
with
346 additions
and
5 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
42 changes: 42 additions & 0 deletions
42
priv/repo/migrations/20250218022011_add_user_with_multitenancy.exs
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,42 @@ | ||
defmodule Example.Repo.Migrations.AddUserWithMultitenancy do | ||
@moduledoc """ | ||
Updates resources based on their most recent snapshots. | ||
This file was autogenerated with `mix ash_postgres.generate_migrations` | ||
""" | ||
|
||
use Ecto.Migration | ||
|
||
def up do | ||
create table(:user_with_multitenancy, primary_key: false) do | ||
add(:id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true) | ||
add(:email, :citext, null: false) | ||
add(:hashed_password, :text) | ||
add(:tenant, :text, null: false) | ||
|
||
add(:created_at, :utc_datetime_usec, | ||
null: false, | ||
default: fragment("(now() AT TIME ZONE 'utc')") | ||
) | ||
|
||
add(:updated_at, :utc_datetime_usec, | ||
null: false, | ||
default: fragment("(now() AT TIME ZONE 'utc')") | ||
) | ||
end | ||
|
||
create unique_index(:user_with_multitenancy, [:tenant, :email], | ||
name: "user_with_multitenancy_email_index" | ||
) | ||
end | ||
|
||
def down do | ||
drop_if_exists( | ||
unique_index(:user_with_multitenancy, [:tenant, :email], | ||
name: "user_with_multitenancy_email_index" | ||
) | ||
) | ||
|
||
drop(table(:user_with_multitenancy)) | ||
end | ||
end |
94 changes: 94 additions & 0 deletions
94
priv/resource_snapshots/repo/user_with_multitenancy/20250218022011.json
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,94 @@ | ||
{ | ||
"attributes": [ | ||
{ | ||
"allow_nil?": false, | ||
"default": "fragment(\"gen_random_uuid()\")", | ||
"generated?": false, | ||
"primary_key?": true, | ||
"references": null, | ||
"size": null, | ||
"source": "id", | ||
"type": "uuid" | ||
}, | ||
{ | ||
"allow_nil?": false, | ||
"default": "nil", | ||
"generated?": false, | ||
"primary_key?": false, | ||
"references": null, | ||
"size": null, | ||
"source": "email", | ||
"type": "citext" | ||
}, | ||
{ | ||
"allow_nil?": true, | ||
"default": "nil", | ||
"generated?": false, | ||
"primary_key?": false, | ||
"references": null, | ||
"size": null, | ||
"source": "hashed_password", | ||
"type": "text" | ||
}, | ||
{ | ||
"allow_nil?": false, | ||
"default": "nil", | ||
"generated?": false, | ||
"primary_key?": false, | ||
"references": null, | ||
"size": null, | ||
"source": "tenant", | ||
"type": "text" | ||
}, | ||
{ | ||
"allow_nil?": false, | ||
"default": "fragment(\"(now() AT TIME ZONE 'utc')\")", | ||
"generated?": false, | ||
"primary_key?": false, | ||
"references": null, | ||
"size": null, | ||
"source": "created_at", | ||
"type": "utc_datetime_usec" | ||
}, | ||
{ | ||
"allow_nil?": false, | ||
"default": "fragment(\"(now() AT TIME ZONE 'utc')\")", | ||
"generated?": false, | ||
"primary_key?": false, | ||
"references": null, | ||
"size": null, | ||
"source": "updated_at", | ||
"type": "utc_datetime_usec" | ||
} | ||
], | ||
"base_filter": null, | ||
"check_constraints": [], | ||
"custom_indexes": [], | ||
"custom_statements": [], | ||
"has_create_action": true, | ||
"hash": "A78FBE6B466C501B7ADFCA26D65967EBBBC9D5503BE161C21455EA3DFEADC486", | ||
"identities": [ | ||
{ | ||
"all_tenants?": false, | ||
"base_filter": null, | ||
"index_name": "user_with_multitenancy_email_index", | ||
"keys": [ | ||
{ | ||
"type": "atom", | ||
"value": "email" | ||
} | ||
], | ||
"name": "email", | ||
"nils_distinct?": true, | ||
"where": null | ||
} | ||
], | ||
"multitenancy": { | ||
"attribute": "tenant", | ||
"global": false, | ||
"strategy": "attribute" | ||
}, | ||
"repo": "Elixir.Example.Repo", | ||
"schema": null, | ||
"table": "user_with_multitenancy" | ||
} |
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
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
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
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
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
Oops, something went wrong.