-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refresh token support implemented
- Loading branch information
1 parent
19e2845
commit 300a89c
Showing
17 changed files
with
3,361 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
CREATE TABLE "access_tokens" ( | ||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | ||
"ip" varchar(39) NOT NULL, | ||
"created_at" timestamp DEFAULT now() NOT NULL, | ||
"revoked_at" timestamp, | ||
"window" interval NOT NULL, | ||
"replaced_by" uuid | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE "refresh_tokens" ( | ||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | ||
"token" varchar(32) NOT NULL, | ||
"user" bigint NOT NULL, | ||
"ip" varchar(39) NOT NULL, | ||
"created_at" timestamp DEFAULT now() NOT NULL, | ||
"replaced_by" uuid, | ||
"revoked_by" bigint, | ||
"window" interval NOT NULL, | ||
"access_token" uuid NOT NULL, | ||
CONSTRAINT "refresh_tokens_token_unique" UNIQUE("token") | ||
); | ||
--> statement-breakpoint | ||
ALTER TABLE "access_tokens" ADD CONSTRAINT "access_tokens_replaced_by_access_tokens_id_fk" FOREIGN KEY ("replaced_by") REFERENCES "public"."access_tokens"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint | ||
ALTER TABLE "refresh_tokens" ADD CONSTRAINT "refresh_tokens_user_users_id_fk" FOREIGN KEY ("user") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint | ||
ALTER TABLE "refresh_tokens" ADD CONSTRAINT "refresh_tokens_replaced_by_refresh_tokens_id_fk" FOREIGN KEY ("replaced_by") REFERENCES "public"."refresh_tokens"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint | ||
ALTER TABLE "refresh_tokens" ADD CONSTRAINT "refresh_tokens_revoked_by_users_id_fk" FOREIGN KEY ("revoked_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint | ||
ALTER TABLE "refresh_tokens" ADD CONSTRAINT "refresh_tokens_access_token_access_tokens_id_fk" FOREIGN KEY ("access_token") REFERENCES "public"."access_tokens"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint | ||
CREATE UNIQUE INDEX "refresh_tokens_token_user_index" ON "refresh_tokens" USING btree ("token","user");--> statement-breakpoint | ||
CREATE VIEW "public"."vw_refresh_tokens" AS (select (created_at + "window")::TIMESTAMP as "expires", "revoked_by", "replaced_by", "created_at", "access_token", "ip", "user", "token", "id" from "refresh_tokens"); |
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,5 @@ | ||
DROP VIEW "public"."vw_refresh_tokens";--> statement-breakpoint | ||
ALTER TABLE "access_tokens" ADD COLUMN "user" bigint NOT NULL;--> statement-breakpoint | ||
ALTER TABLE "access_tokens" ADD CONSTRAINT "access_tokens_user_users_id_fk" FOREIGN KEY ("user") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint | ||
CREATE VIEW "public"."vw_access_tokens" AS (select "user", (now() > (created_at + "window")::TIMESTAMP)::BOOLEAN OR replaced_by IS NOT NULL as "is_expired", (created_at + "window")::TIMESTAMP as "expires_at", "created_at", "ip", "id" from "access_tokens");--> statement-breakpoint | ||
CREATE VIEW "public"."vw_refresh_tokens" AS (select (now()::TIMESTAMP > (created_at + "window")::TIMESTAMP)::BOOLEAN as "is_expired", (created_at + "window")::TIMESTAMP as "expires", "revoked_by", "replaced_by", "created_at", "access_token", "ip", "user", "token", "id" from "refresh_tokens"); |
Oops, something went wrong.