Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit a2a1150

Browse files
committed
feat: impl basic auth (#62)
1 parent 174206b commit a2a1150

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2239
-128
lines changed

.github/workflows/test-all.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88
jobs:
99
build:
1010
runs-on: ubuntu-20.04
11+
timeout-minutes: 5
1112
steps:
1213
# Checkout registry repo
1314
- name: Checkout registry Repo

deno.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"fmt": {
3+
"useTabs": true
4+
}
5+
}

modules/auth/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface Config {
2+
email?: EmailConfig;
3+
}
4+
5+
export interface EmailConfig {
6+
fromEmail: string;
7+
fromName?: string;
8+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
-- CreateTable
2+
CREATE TABLE "Identity" (
3+
"userId" UUID NOT NULL,
4+
"createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
5+
"deletedAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
6+
7+
CONSTRAINT "Identity_pkey" PRIMARY KEY ("userId")
8+
);
9+
10+
-- CreateTable
11+
CREATE TABLE "EmailPasswordless" (
12+
"id" UUID NOT NULL,
13+
"identityId" UUID NOT NULL,
14+
"email" TEXT NOT NULL,
15+
"createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
16+
17+
CONSTRAINT "EmailPasswordless_pkey" PRIMARY KEY ("id")
18+
);
19+
20+
-- CreateTable
21+
CREATE TABLE "EmailPasswordlessVerification" (
22+
"id" UUID NOT NULL,
23+
"identityId" UUID,
24+
"email" TEXT NOT NULL,
25+
"code" TEXT NOT NULL,
26+
"attemptCount" INTEGER NOT NULL DEFAULT 0,
27+
"maxAttemptCount" INTEGER NOT NULL,
28+
"createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
29+
"expireAt" TIMESTAMP NOT NULL,
30+
"completedAt" TIMESTAMP,
31+
32+
CONSTRAINT "EmailPasswordlessVerification_pkey" PRIMARY KEY ("id")
33+
);
34+
35+
-- CreateIndex
36+
CREATE UNIQUE INDEX "EmailPasswordless_email_key" ON "EmailPasswordless"("email");
37+
38+
-- CreateIndex
39+
CREATE UNIQUE INDEX "EmailPasswordlessVerification_code_key" ON "EmailPasswordlessVerification"("code");
40+
41+
-- AddForeignKey
42+
ALTER TABLE "EmailPasswordless" ADD CONSTRAINT "EmailPasswordless_identityId_fkey" FOREIGN KEY ("identityId") REFERENCES "Identity"("userId") ON DELETE RESTRICT ON UPDATE CASCADE;
43+
44+
-- AddForeignKey
45+
ALTER TABLE "EmailPasswordlessVerification" ADD CONSTRAINT "EmailPasswordlessVerification_email_fkey" FOREIGN KEY ("email") REFERENCES "EmailPasswordless"("email") ON DELETE RESTRICT ON UPDATE CASCADE;
46+
47+
-- AddForeignKey
48+
ALTER TABLE "EmailPasswordlessVerification" ADD CONSTRAINT "EmailPasswordlessVerification_identityId_fkey" FOREIGN KEY ("identityId") REFERENCES "Identity"("userId") ON DELETE SET NULL ON UPDATE CASCADE;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `identityId` on the `EmailPasswordlessVerification` table. All the data in the column will be lost.
5+
6+
*/
7+
-- DropForeignKey
8+
ALTER TABLE "EmailPasswordlessVerification" DROP CONSTRAINT "EmailPasswordlessVerification_identityId_fkey";
9+
10+
-- AlterTable
11+
ALTER TABLE "EmailPasswordlessVerification" DROP COLUMN "identityId",
12+
ADD COLUMN "userId" UUID;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- DropForeignKey
2+
ALTER TABLE "EmailPasswordlessVerification" DROP CONSTRAINT "EmailPasswordlessVerification_email_fkey";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `identityId` on the `EmailPasswordless` table. All the data in the column will be lost.
5+
- You are about to drop the `Identity` table. If the table is not empty, all the data it contains will be lost.
6+
- A unique constraint covering the columns `[userId]` on the table `EmailPasswordless` will be added. If there are existing duplicate values, this will fail.
7+
- Added the required column `userId` to the `EmailPasswordless` table without a default value. This is not possible if the table is not empty.
8+
9+
*/
10+
-- DropForeignKey
11+
ALTER TABLE "EmailPasswordless" DROP CONSTRAINT "EmailPasswordless_identityId_fkey";
12+
13+
-- AlterTable
14+
ALTER TABLE "EmailPasswordless" DROP COLUMN "identityId",
15+
ADD COLUMN "userId" UUID NOT NULL;
16+
17+
-- DropTable
18+
DROP TABLE "Identity";
19+
20+
-- CreateIndex
21+
CREATE UNIQUE INDEX "EmailPasswordless_userId_key" ON "EmailPasswordless"("userId");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Please do not edit this file manually
2+
# It should be added in your version-control system (i.e. Git)
3+
provider = "postgresql"

modules/auth/db/schema.prisma

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
datasource db {
2+
provider = "postgresql"
3+
url = env("DATABASE_URL")
4+
}
5+
6+
model EmailPasswordless {
7+
id String @id @default(uuid()) @db.Uuid
8+
userId String @db.Uuid @unique
9+
email String @unique
10+
createdAt DateTime @default(now()) @db.Timestamp
11+
}
12+
13+
model EmailPasswordlessVerification {
14+
id String @id @default(uuid()) @db.Uuid
15+
16+
// If exists, link to existing identity. If null, create new identity.
17+
userId String? @db.Uuid
18+
19+
email String
20+
21+
// Code the user has to input to verify the email
22+
code String @unique
23+
24+
attemptCount Int @default(0)
25+
maxAttemptCount Int
26+
27+
createdAt DateTime @default(now()) @db.Timestamp
28+
expireAt DateTime @db.Timestamp
29+
completedAt DateTime? @db.Timestamp
30+
}

modules/auth/module.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
dependencies:
2+
email: {}
3+
users: {}
4+
rate_limit: {}
5+
scripts:
6+
auth_email_passwordless:
7+
public: true
8+
verify_email_passwordless:
9+
public: true
10+
errors:
11+
PROVIDER_DISABLED: {}
12+
VERIFICATION_CODE_INVALID: {}
13+
VERIFICATION_CODE_ATTEMPT_LIMIT: {}
14+
VERIFICATION_CODE_EXPIRED: {}
15+
VERIFICATION_CODE_ALREADY_USED: {}
16+
EMAIL_ALREADY_USED: {}

0 commit comments

Comments
 (0)