@arkstack/auth 0.13.2 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Encryption, Exception, Hash, env, getModel } from "@arkstack/common";
1
+ import { Encryption, Exception, Hash, appKey, env, getModel } from "@arkstack/common";
2
2
  import { SignJWT, jwtVerify } from "jose";
3
3
  import { Request, Response, Session } from "@arkstack/http";
4
4
  import { UAParser } from "ua-parser-js";
@@ -543,7 +543,7 @@ var Auth = class Auth extends AuthContract {
543
543
  }
544
544
  }
545
545
  getSecret() {
546
- return this.configuredSecret ?? env("JWT_SECRET", "default_secret");
546
+ return this.configuredSecret ?? appKey("JWT_SECRET") ?? "default_secret";
547
547
  }
548
548
  setAuthenticated(user, token) {
549
549
  this.#user = user;
@@ -0,0 +1 @@
1
+ export { };
package/dist/setup.js ADDED
@@ -0,0 +1,25 @@
1
+ import { Publisher } from "@arkstack/common";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ //#region src/setup.ts
5
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
6
+ /**
7
+ * Register the artifacts `@arkstack/auth` publishes into the application.
8
+ *
9
+ * Run `ark publish --tag two-factor` (or `--package @arkstack/auth`) to copy the
10
+ * `UserTwoFactor` model and the migration that creates the `user_two_factors`
11
+ * table into the app.
12
+ */
13
+ Publisher.publishes({
14
+ package: "@arkstack/auth",
15
+ tag: "two-factor",
16
+ entries: [{
17
+ from: join(root, "stubs/models/UserTwoFactor.ts.stub"),
18
+ to: "src/app/models/UserTwoFactor.ts"
19
+ }, {
20
+ from: join(root, "stubs/migrations/20260505110000_create_user_two_factors_table.ts.stub"),
21
+ to: "src/database/migrations/20260505110000_create_user_two_factors_table.ts"
22
+ }]
23
+ });
24
+ //#endregion
25
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/auth",
3
- "version": "0.13.2",
3
+ "version": "0.14.0",
4
4
  "type": "module",
5
5
  "description": "Authentication module for Arkstack, providing core authentication and identity features.",
6
6
  "homepage": "https://arkstack.toneflix.net/guide/auth",
@@ -25,25 +25,27 @@
25
25
  "arkstack"
26
26
  ],
27
27
  "files": [
28
- "dist"
28
+ "dist",
29
+ "stubs"
29
30
  ],
30
31
  "publishConfig": {
31
32
  "access": "public"
32
33
  },
33
34
  "exports": {
34
35
  ".": "./dist/index.js",
36
+ "./setup": "./dist/setup.js",
35
37
  "./package.json": "./package.json"
36
38
  },
37
39
  "dependencies": {
38
40
  "jose": "^6.2.3",
39
41
  "otpauth": "^9.5.1",
40
42
  "ua-parser-js": "^2.0.9",
41
- "@arkstack/common": "^0.13.2",
42
- "@arkstack/http": "^0.13.2"
43
+ "@arkstack/common": "^0.14.0",
44
+ "@arkstack/http": "^0.14.0"
43
45
  },
44
46
  "peerDependencies": {
45
47
  "@h3ravel/support": "^2.1.3",
46
- "@arkstack/database": "^0.13.2"
48
+ "@arkstack/database": "^0.14.0"
47
49
  },
48
50
  "scripts": {
49
51
  "build": "tsdown --config-loader unrun",
@@ -0,0 +1,24 @@
1
+ import { Migration, SchemaBuilder } from 'arkormx'
2
+
3
+ export default class CreateUserTwoFactorsTableMigration extends Migration {
4
+ public async up (schema: SchemaBuilder): Promise<void> {
5
+ schema.createTable('user_two_factors', (table) => {
6
+ table.id('id', 'uuid').primary()
7
+ table.uuid('userId').map('user_id')
8
+ .foreign().references('users', 'id').onDelete('cascade').as('user').inverseAlias('twoFactor')
9
+ table.enum('method', ['authenticator', 'sms']).nullable().enumName('TwoFactorMethod')
10
+ table.string('secretCiphertext').nullable().map('secret_ciphertext')
11
+ table.string('smsCodeHash').nullable().map('sms_code_hash')
12
+ table.date('smsCodeExpiresAt').nullable().map('sms_code_expires_at')
13
+ table.string('smsCodePurpose').nullable().map('sms_code_purpose')
14
+ table.date('enabledAt').nullable().map('enabled_at')
15
+ table.json('recoveryCodeHashes').nullable().map('recovery_code_hashes')
16
+ table.timestamps()
17
+ table.index(['userId'])
18
+ })
19
+ }
20
+
21
+ public async down (schema: SchemaBuilder): Promise<void> {
22
+ schema.dropTable('user_two_factors')
23
+ }
24
+ }
@@ -0,0 +1,20 @@
1
+ import { UserTwoFactor as BaseUserTwoFactor } from '@arkstack/auth'
2
+ import { User } from '@app/models/User'
3
+
4
+ export class UserTwoFactor extends BaseUserTwoFactor {
5
+ protected static columns = {
6
+ userId: 'user_id',
7
+ secretCiphertext: 'secret_ciphertext',
8
+ smsCodeHash: 'sms_code_hash',
9
+ smsCodeExpiresAt: 'sms_code_expires_at',
10
+ smsCodePurpose: 'sms_code_purpose',
11
+ enabledAt: 'enabled_at',
12
+ recoveryCodeHashes: 'recovery_code_hashes',
13
+ createdAt: 'created_at',
14
+ updatedAt: 'updated_at',
15
+ }
16
+
17
+ user() {
18
+ return this.belongsTo(User, 'userId', 'id')
19
+ }
20
+ }