Skip to content

Commit

Permalink
Orion signup flow rework (#321)
Browse files Browse the repository at this point in the history
* Add graphql schema changes

* regenerate DB migrations

* opdate openapi.yaml file

* updated authHandler function

* remove /confirm-email auth api endpoint

* [auth-api] update /change-account endpoint implementation

* [auth-api] update create account endpoint

* [auth-api] update /request-email-confirmation-token endpoint

* update mappings due to schema changes

* update custon resolvers due to schema changes

* added createAccountMembership custom mutation

* update auth-server, mail scheduler and notification tests

* update auth-api docs

* small refactor

* fix: auth-api unit tests

* fix: lint errors

* move encryption_artifacts & session_encryption_artifacts to admin schema

* bump package version

* fix: Members.MemberAccountsUpdated mappings bug

* [offchainState] add v5.0.0 migrations

* rename joystreamAccount to joystreamAccountId in 'AccountData' graphql type

* add 'signupType' param to email confirmation link
  • Loading branch information
zeeshanakram3 authored Aug 3, 2024
1 parent 5eeeb68 commit fbd245e
Show file tree
Hide file tree
Showing 55 changed files with 1,026 additions and 838 deletions.
9 changes: 8 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ MAX_CACHED_ENTITIES=1000
APP_PRIVATE_KEY=this-is-not-so-secret-change-it
SESSION_EXPIRY_AFTER_INACTIVITY_MINUTES=60
SESSION_MAX_DURATION_HOURS=720
EMAIL_CONFIRMATION_ROUTE=http://localhost:4074/api/v1/confirm-email?token={token}
EMAIL_CONFIRMATION_ROUTE="http://localhost:4074/api/v1/confirm-email?token={token}&expiry={expiry}&signupType={signupType}"
EMAIL_CONFIRMATION_TOKEN_EXPIRY_TIME_HOURS=24
EMAIL_CONFIRMATION_TOKEN_RATE_LIMIT=5
ACCOUNT_OWNERSHIP_PROOF_EXPIRY_TIME_SECONDS=300 # 5 minutes
Expand Down Expand Up @@ -79,6 +79,13 @@ APP_ASSET_STORAGE=https://raw.githubusercontent.com/Joystream/atlas-notification
APP_NAME_ALT=Gleev.xyz
NOTIFICATION_ASSET_ROOT=https://raw.githubusercontent.com/Joystream/atlas-notification-assets/main/icons

# =====================================================================================
# Faucet config
# =====================================================================================

FAUCET_URL=http://localhost:3002/register
FAUCET_CAPTCHA_BYPASS_KEY=faucet-captcha-bypass-key

# =====================================================================================
# Telemetry
# =====================================================================================
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ db/migrations/*-Views.js
schema.graphql
/scripts/orion-v1-migration/data
/db/export
src/auth-server/generated
src/auth-server/emails/templates/preview
20 changes: 10 additions & 10 deletions db/migrations/1708169663879-Data.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions db/migrations/1722676430400-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = class Data1722676430400 {
name = 'Data1722676430400'

async up(db) {
await db.query(`ALTER TABLE "admin"."account" DROP CONSTRAINT "FK_601b93655bcbe73cb58d8c80cd3"`)
await db.query(`DROP INDEX "admin"."IDX_601b93655bcbe73cb58d8c80cd"`)
await db.query(`DROP INDEX "admin"."IDX_df4da05a7a80c1afd18b8f0990"`)
await db.query(`ALTER TABLE "membership" RENAME COLUMN "controller_account" TO "controller_account_id"`)
await db.query(`CREATE TABLE "blockchain_account" ("id" character varying NOT NULL, CONSTRAINT "PK_3d07d692a436bc34ef4093d9c60" PRIMARY KEY ("id"))`)
await db.query(`CREATE TABLE "admin"."email_confirmation_token" ("id" character varying NOT NULL, "issued_at" TIMESTAMP WITH TIME ZONE NOT NULL, "expiry" TIMESTAMP WITH TIME ZONE NOT NULL, "email" text NOT NULL, CONSTRAINT "PK_2fa8d5586af7e96201b84492131" PRIMARY KEY ("id"))`)
await db.query(`ALTER TABLE "admin"."account" DROP COLUMN "is_email_confirmed"`)
await db.query(`ALTER TABLE "admin"."account" DROP CONSTRAINT "Account_membership"`)
await db.query(`ALTER TABLE "admin"."account" DROP COLUMN "membership_id"`)
await db.query(`ALTER TABLE "admin"."account" DROP CONSTRAINT "Account_joystreamAccount"`)
await db.query(`ALTER TABLE "admin"."account" DROP COLUMN "joystream_account"`)
await db.query(`ALTER TABLE "admin"."account" DROP COLUMN "referrer_channel_id"`)
await db.query(`ALTER TABLE "admin"."account" ADD "joystream_account_id" character varying NOT NULL`)
await db.query(`ALTER TABLE "admin"."account" ADD CONSTRAINT "UQ_90debbc4217372d2464201c576a" UNIQUE ("joystream_account_id")`)
await db.query(`ALTER TABLE "membership" DROP COLUMN "controller_account_id"`)
await db.query(`ALTER TABLE "membership" ADD "controller_account_id" character varying`)
await db.query(`CREATE INDEX "IDX_58492b909a36e6a3e4dabd4674" ON "membership" ("controller_account_id") `)
await db.query(`CREATE INDEX "IDX_90debbc4217372d2464201c576" ON "admin"."account" ("joystream_account_id") `)
await db.query(`ALTER TABLE "membership" ADD CONSTRAINT "FK_58492b909a36e6a3e4dabd46743" FOREIGN KEY ("controller_account_id") REFERENCES "blockchain_account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED`)
await db.query(`ALTER TABLE "admin"."account" ADD CONSTRAINT "FK_90debbc4217372d2464201c576a" FOREIGN KEY ("joystream_account_id") REFERENCES "blockchain_account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED`)
}

async down(db) {
await db.query(`ALTER TABLE "admin"."account" ADD CONSTRAINT "FK_601b93655bcbe73cb58d8c80cd3" FOREIGN KEY ("membership_id") REFERENCES "membership"("id") ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED`)
await db.query(`CREATE INDEX "IDX_601b93655bcbe73cb58d8c80cd" ON "admin"."account" ("membership_id") `)
await db.query(`CREATE INDEX "IDX_df4da05a7a80c1afd18b8f0990" ON "admin"."account" ("joystream_account") `)
await db.query(`ALTER TABLE "membership" RENAME COLUMN "controller_account_id" TO "controller_account"`)
await db.query(`DROP TABLE "blockchain_account"`)
await db.query(`DROP TABLE "admin"."email_confirmation_token"`)
await db.query(`ALTER TABLE "admin"."account" ADD "is_email_confirmed" boolean NOT NULL`)
await db.query(`ALTER TABLE "admin"."account" ADD CONSTRAINT "Account_membership" UNIQUE ("membership_id")`)
await db.query(`ALTER TABLE "admin"."account" ADD "membership_id" character varying NOT NULL`)
await db.query(`ALTER TABLE "admin"."account" ADD CONSTRAINT "Account_joystreamAccount" UNIQUE ("joystream_account")`)
await db.query(`ALTER TABLE "admin"."account" ADD "joystream_account" text NOT NULL`)
await db.query(`ALTER TABLE "admin"."account" ADD "referrer_channel_id" text`)
await db.query(`ALTER TABLE "admin"."account" DROP COLUMN "joystream_account_id"`)
await db.query(`ALTER TABLE "admin"."account" DROP CONSTRAINT "UQ_90debbc4217372d2464201c576a"`)
await db.query(`ALTER TABLE "membership" ADD "controller_account_id" text NOT NULL`)
await db.query(`ALTER TABLE "membership" DROP COLUMN "controller_account_id"`)
await db.query(`DROP INDEX "public"."IDX_58492b909a36e6a3e4dabd4674"`)
await db.query(`DROP INDEX "admin"."IDX_90debbc4217372d2464201c576"`)
await db.query(`ALTER TABLE "membership" DROP CONSTRAINT "FK_58492b909a36e6a3e4dabd46743"`)
await db.query(`ALTER TABLE "admin"."account" DROP CONSTRAINT "FK_90debbc4217372d2464201c576a"`)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

const { getViewDefinitions } = require('../viewDefinitions')

module.exports = class Views1721141313757 {
name = 'Views1721141313757'
module.exports = class Views1722676430521 {
name = 'Views1722676430521'

async up(db) {
// these two queries will be invoked and the cleaned up by the squid itself
Expand Down
1 change: 1 addition & 0 deletions docker.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ DB_HOST=orion_db
PROCESSOR_HOST=orion_processor
# Archive gateway host&port (can be overriden via local env)
ARCHIVE_GATEWAY_URL=${CUSTOM_ARCHIVE_GATEWAY_URL:-http://orion_archive_gateway:8000/graphql}
# ARCHIVE_GATEWAY_URL=${CUSTOM_ARCHIVE_GATEWAY_URL:-https://archive.joystream.org/graphql}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orion",
"version": "4.0.6",
"version": "5.0.0",
"engines": {
"node": ">=16"
},
Expand Down
40 changes: 26 additions & 14 deletions schema/auth.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type User @entity @schema(name: "admin") {
nftFeaturingRequests: [NftFeaturingRequest!]! @derivedFrom(field: "user")
}

type EncryptionArtifacts @entity {
type EncryptionArtifacts @entity @schema(name: "admin") {
"ID / lookupKey"
id: ID!

Expand All @@ -55,7 +55,7 @@ type EncryptionArtifacts @entity {
encryptedSeed: String!
}

type SessionEncryptionArtifacts @entity {
type SessionEncryptionArtifacts @entity @schema(name: "admin") {
"Unique identifier"
id: ID!

Expand Down Expand Up @@ -112,31 +112,20 @@ type Account @entity @schema(name: "admin") {
"Gateway account's e-mail address"
email: String! @unique

"""
Indicates whether the gateway account's e-mail has been confirmed or not.
"""
isEmailConfirmed: Boolean!

"Indicates whether the access to the gateway account is blocked"
isBlocked: Boolean!

"Time when the gateway account was registered"
registeredAt: DateTime!

"On-chain membership associated with the gateway account"
membership: Membership! @unique

"Blockchain (joystream) account associated with the gateway account"
joystreamAccount: String! @unique
joystreamAccount: BlockchainAccount! @unique

"runtime notifications"
notifications: [Notification!]! @derivedFrom(field: "account")

"notification preferences for the account"
notificationPreferences: AccountNotificationPreferences!

"ID of the channel which referred the user to the platform"
referrerChannelId: String
}

type AccountNotificationPreferences {
Expand Down Expand Up @@ -214,3 +203,26 @@ type Token @entity @schema(name: "admin") {
"The account the token was issued for"
issuedFor: Account!
}

type EmailConfirmationToken @entity @schema(name: "admin") {
"The token itself (32-byte string, securely random)"
id: ID!

"When was the token issued"
issuedAt: DateTime!

"When does the token expire or when has it expired"
expiry: DateTime!

# "The User the token was issued for"
# issuedFor: User!

"The email the token was issued for"
email: String!

# "Indicates whether the token has been confirmed or not"
# isConfirmed: Boolean!

# "Time when the token was confirmed"
# confirmedAt: DateTime
}
10 changes: 9 additions & 1 deletion schema/membership.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ type AvatarUri @variant {
avatarUri: String!
}

type BlockchainAccount @entity {
"The blockchain account id/address"
id: ID!

"Membership associated with the blockchain account (controllerAccount)"
memberships: [Membership!] @derivedFrom(field: "controllerAccount")
}

union Avatar = AvatarObject | AvatarUri

type MemberMetadata @entity {
Expand Down Expand Up @@ -41,7 +49,7 @@ type Membership @entity {
metadata: MemberMetadata @derivedFrom(field: "member")

"Member's controller account id"
controllerAccount: String!
controllerAccount: BlockchainAccount!

"Auctions in which is this user whitelisted to participate"
whitelistedInAuctions: [AuctionWhitelistedMember!] @derivedFrom(field: "member")
Expand Down
1 change: 0 additions & 1 deletion src/auth-server/docs/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Models/AnonymousUserAuthResponseData.md
Models/AnonymousUserAuthResponseData_allOf.md
Models/ChangeAccountRequestData.md
Models/ChangeAccountRequestData_allOf.md
Models/ConfirmEmailRequestData.md
Models/CreateAccountRequestData.md
Models/CreateAccountRequestData_allOf.md
Models/EncryptionArtifacts.md
Expand Down
Loading

0 comments on commit fbd245e

Please sign in to comment.