firstly 0.0.3 → 0.0.5
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/CHANGELOG.md +21 -0
- package/esm/{KitBaseEnum.d.ts → BaseEnum.d.ts} +18 -9
- package/esm/{KitBaseEnum.js → BaseEnum.js} +2 -13
- package/esm/{KitEntity.d.ts → FF_Entity.d.ts} +1 -1
- package/esm/{KitEntity.js → FF_Entity.js} +9 -9
- package/esm/{KitFields.d.ts → FF_Fields.d.ts} +4 -5
- package/esm/{KitFields.js → FF_Fields.js} +41 -55
- package/esm/ROUTES.d.ts +4 -2
- package/esm/ROUTES.js +4 -7
- package/esm/SqlDatabase/FF_LogToConsole.d.ts +1 -0
- package/esm/SqlDatabase/{LogToConsoleCustom.js → FF_LogToConsole.js} +1 -1
- package/esm/api/index.d.ts +1 -0
- package/esm/auth/Adapter.js +10 -8
- package/esm/auth/{AuthController.d.ts → AuthController.server.d.ts} +2 -2
- package/esm/auth/{AuthController.js → AuthController.server.js} +15 -51
- package/esm/auth/Entities.d.ts +18 -17
- package/esm/auth/Entities.js +66 -63
- package/esm/auth/README.md +13 -0
- package/esm/auth/{RoleController.d.ts → RoleHelpers.d.ts} +2 -4
- package/esm/auth/RoleHelpers.js +43 -0
- package/esm/auth/client/Auth.d.ts +69 -0
- package/esm/auth/client/Auth.js +121 -0
- package/esm/auth/client/index.d.ts +2 -0
- package/esm/auth/client/index.js +2 -0
- package/esm/auth/index.d.ts +10 -11
- package/esm/auth/index.js +37 -21
- package/esm/auth/providers/github.d.ts +22 -17
- package/esm/auth/providers/github.js +29 -15
- package/esm/auth/providers/strava.d.ts +22 -17
- package/esm/auth/providers/strava.js +23 -15
- package/esm/auth/static/assets/{Page-BwHye0GW.d.ts → Page-BYzkK4q3.d.ts} +1 -1
- package/esm/auth/static/assets/{Page-BwHye0GW.js → Page-BYzkK4q3.js} +1 -1
- package/esm/auth/static/assets/Page-ByIhtXVt.d.ts +5 -0
- package/esm/auth/static/assets/Page-ByIhtXVt.js +8190 -0
- package/esm/auth/static/assets/{Page-BMOLAIFx.d.ts → Page-Do7F0Mzd.d.ts} +1 -1
- package/esm/auth/static/assets/{Page-BMOLAIFx.js → Page-Do7F0Mzd.js} +1 -1
- package/esm/auth/static/assets/index-czJ1PA1n.js +2 -0
- package/esm/auth/static/index.html +1 -1
- package/esm/bin/cmd.js +182 -83
- package/esm/cellsBuildor.d.ts +45 -0
- package/esm/{kitCellsBuildor.js → cellsBuildor.js} +24 -14
- package/esm/feedback/ui/DialogIssue.svelte +2 -2
- package/esm/formats/dates.js +2 -2
- package/esm/formats/strings.js +0 -11
- package/esm/handle/index.d.ts +1 -0
- package/esm/helper.d.ts +8 -10
- package/esm/helper.js +13 -12
- package/esm/index.d.ts +37 -48
- package/esm/index.js +29 -20
- package/esm/{kitStoreItem.d.ts → storeItem.d.ts} +1 -1
- package/esm/{kitStoreItem.js → storeItem.js} +3 -3
- package/esm/{kitStoreList.d.ts → storeList.d.ts} +4 -4
- package/esm/{kitStoreList.js → storeList.js} +1 -1
- package/esm/ui/Button.svelte +7 -9
- package/esm/ui/Button.svelte.d.ts +2 -2
- package/esm/ui/Field.svelte +9 -8
- package/esm/ui/Field.svelte.d.ts +2 -2
- package/esm/ui/FieldGroup.svelte +5 -3
- package/esm/ui/FieldGroup.svelte.d.ts +4 -4
- package/esm/ui/Grid.svelte.d.ts +5 -5
- package/esm/ui/GridPaginate.svelte +3 -6
- package/esm/ui/Icon.svelte +6 -7
- package/esm/ui/LibIcon.js +0 -2
- package/esm/ui/dialog/DialogForm.svelte +5 -6
- package/esm/ui/dialog/DialogPrimitive.svelte.d.ts +2 -2
- package/esm/ui/dialog/FormEditAction.svelte.d.ts +2 -2
- package/esm/ui/dialog/dialog.d.ts +7 -5
- package/esm/ui/dialog/dialog.js +1 -0
- package/esm/ui/index.d.ts +2 -2
- package/esm/ui/internals/FieldContainer.svelte +1 -1
- package/esm/ui/internals/Input.svelte +1 -1
- package/esm/ui/internals/select/MultiSelectMelt.svelte +16 -19
- package/esm/ui/internals/select/MultiSelectMelt.svelte.d.ts +3 -3
- package/esm/ui/internals/select/SelectMelt.svelte +10 -14
- package/esm/ui/internals/select/SelectMelt.svelte.d.ts +3 -3
- package/esm/ui/internals/select/SelectRadio.svelte.d.ts +2 -2
- package/esm/ui/link/LinkPlus.svelte.d.ts +2 -2
- package/esm/utils/types.d.ts +0 -15
- package/esm/utils/types.js +1 -17
- package/esm/virtual/Customer.js +2 -2
- package/esm/virtual/FilterEntity.js +1 -1
- package/esm/virtual/StateDemoEnum.d.ts +4 -4
- package/esm/virtual/StateDemoEnum.js +2 -2
- package/esm/virtual/UIEntity.js +4 -4
- package/esm/vite/index.js +1 -1
- package/package.json +10 -5
- package/esm/SqlDatabase/LogToConsoleCustom.d.ts +0 -1
- package/esm/auth/RoleController.js +0 -57
- package/esm/auth/static/assets/Page-BMFREPjF.d.ts +0 -5
- package/esm/auth/static/assets/Page-BMFREPjF.js +0 -18
- package/esm/auth/static/assets/index-CKmKKRRL.js +0 -2
- package/esm/kitCellsBuildor.d.ts +0 -45
- /package/esm/auth/static/assets/{index-CKmKKRRL.d.ts → index-czJ1PA1n.d.ts} +0 -0
package/esm/auth/Entities.js
CHANGED
|
@@ -4,17 +4,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var
|
|
7
|
+
var FFAuthProvider_1;
|
|
8
8
|
import { Entity, Fields, Relations, Validators, ValueListFieldType } from 'remult';
|
|
9
|
-
import {
|
|
10
|
-
export const
|
|
11
|
-
Admin: '
|
|
9
|
+
import { BaseEnum, FF_Role } from '../';
|
|
10
|
+
export const FF_Auth_Role = {
|
|
11
|
+
Admin: 'FF_Auth_Role.Admin',
|
|
12
12
|
};
|
|
13
|
-
let
|
|
13
|
+
let FFAuthUser = class FFAuthUser {
|
|
14
14
|
id;
|
|
15
15
|
createdAt;
|
|
16
16
|
updatedAt;
|
|
17
|
-
// @Fields.string<KitAuthUser>({
|
|
18
17
|
name;
|
|
19
18
|
roles = [];
|
|
20
19
|
accounts;
|
|
@@ -22,13 +21,13 @@ let KitAuthUser = class KitAuthUser {
|
|
|
22
21
|
};
|
|
23
22
|
__decorate([
|
|
24
23
|
Fields.cuid()
|
|
25
|
-
],
|
|
24
|
+
], FFAuthUser.prototype, "id", void 0);
|
|
26
25
|
__decorate([
|
|
27
26
|
Fields.createdAt()
|
|
28
|
-
],
|
|
27
|
+
], FFAuthUser.prototype, "createdAt", void 0);
|
|
29
28
|
__decorate([
|
|
30
29
|
Fields.updatedAt()
|
|
31
|
-
],
|
|
30
|
+
], FFAuthUser.prototype, "updatedAt", void 0);
|
|
32
31
|
__decorate([
|
|
33
32
|
Fields.string({
|
|
34
33
|
validate: [
|
|
@@ -39,7 +38,7 @@ __decorate([
|
|
|
39
38
|
},
|
|
40
39
|
],
|
|
41
40
|
})
|
|
42
|
-
],
|
|
41
|
+
], FFAuthUser.prototype, "name", void 0);
|
|
43
42
|
__decorate([
|
|
44
43
|
Fields.object({
|
|
45
44
|
valueConverter: {
|
|
@@ -47,71 +46,75 @@ __decorate([
|
|
|
47
46
|
fromDb: (x) => (x ? x.split(',') : undefined),
|
|
48
47
|
},
|
|
49
48
|
})
|
|
50
|
-
],
|
|
49
|
+
], FFAuthUser.prototype, "roles", void 0);
|
|
51
50
|
__decorate([
|
|
52
|
-
Relations.toMany(() =>
|
|
53
|
-
],
|
|
51
|
+
Relations.toMany(() => FFAuthAccount, 'userId')
|
|
52
|
+
], FFAuthUser.prototype, "accounts", void 0);
|
|
54
53
|
__decorate([
|
|
55
|
-
Relations.toMany(() =>
|
|
56
|
-
],
|
|
57
|
-
|
|
58
|
-
Entity('
|
|
59
|
-
allowApiCrud: [
|
|
60
|
-
|
|
54
|
+
Relations.toMany(() => FFAuthUserSession, 'userId')
|
|
55
|
+
], FFAuthUser.prototype, "sessions", void 0);
|
|
56
|
+
FFAuthUser = __decorate([
|
|
57
|
+
Entity('ff_auth.users', {
|
|
58
|
+
allowApiCrud: [FF_Auth_Role.Admin, FF_Role.Admin],
|
|
59
|
+
caption: 'Auth - Users',
|
|
61
60
|
})
|
|
62
|
-
],
|
|
63
|
-
export {
|
|
64
|
-
let
|
|
61
|
+
], FFAuthUser);
|
|
62
|
+
export { FFAuthUser };
|
|
63
|
+
let FFAuthAccount = class FFAuthAccount {
|
|
64
|
+
id;
|
|
65
65
|
createdAt;
|
|
66
66
|
updatedAt;
|
|
67
67
|
userId;
|
|
68
68
|
user;
|
|
69
|
-
provider =
|
|
69
|
+
provider = FFAuthProvider.PASSWORD.id;
|
|
70
70
|
providerUserId = '';
|
|
71
71
|
hashPassword;
|
|
72
72
|
token;
|
|
73
73
|
expiresAt;
|
|
74
74
|
lastVerifiedAt;
|
|
75
75
|
};
|
|
76
|
+
__decorate([
|
|
77
|
+
Fields.cuid()
|
|
78
|
+
], FFAuthAccount.prototype, "id", void 0);
|
|
76
79
|
__decorate([
|
|
77
80
|
Fields.createdAt()
|
|
78
|
-
],
|
|
81
|
+
], FFAuthAccount.prototype, "createdAt", void 0);
|
|
79
82
|
__decorate([
|
|
80
83
|
Fields.updatedAt()
|
|
81
|
-
],
|
|
84
|
+
], FFAuthAccount.prototype, "updatedAt", void 0);
|
|
82
85
|
__decorate([
|
|
83
86
|
Fields.string()
|
|
84
|
-
],
|
|
87
|
+
], FFAuthAccount.prototype, "userId", void 0);
|
|
85
88
|
__decorate([
|
|
86
|
-
Relations.toOne(() =>
|
|
87
|
-
],
|
|
89
|
+
Relations.toOne(() => FFAuthUser, 'userId')
|
|
90
|
+
], FFAuthAccount.prototype, "user", void 0);
|
|
88
91
|
__decorate([
|
|
89
92
|
Fields.string()
|
|
90
|
-
],
|
|
93
|
+
], FFAuthAccount.prototype, "provider", void 0);
|
|
91
94
|
__decorate([
|
|
92
95
|
Fields.string()
|
|
93
|
-
],
|
|
96
|
+
], FFAuthAccount.prototype, "providerUserId", void 0);
|
|
94
97
|
__decorate([
|
|
95
98
|
Fields.string({ includeInApi: false, allowNull: true })
|
|
96
|
-
],
|
|
99
|
+
], FFAuthAccount.prototype, "hashPassword", void 0);
|
|
97
100
|
__decorate([
|
|
98
101
|
Fields.string({ includeInApi: false, allowNull: true })
|
|
99
|
-
],
|
|
102
|
+
], FFAuthAccount.prototype, "token", void 0);
|
|
100
103
|
__decorate([
|
|
101
104
|
Fields.date({ includeInApi: false, allowNull: true })
|
|
102
|
-
],
|
|
105
|
+
], FFAuthAccount.prototype, "expiresAt", void 0);
|
|
103
106
|
__decorate([
|
|
104
107
|
Fields.date({ includeInApi: false, allowNull: true })
|
|
105
|
-
],
|
|
106
|
-
|
|
107
|
-
Entity('
|
|
108
|
-
allowApiCrud: [
|
|
109
|
-
|
|
110
|
-
id: { provider: true, userId: true },
|
|
108
|
+
], FFAuthAccount.prototype, "lastVerifiedAt", void 0);
|
|
109
|
+
FFAuthAccount = __decorate([
|
|
110
|
+
Entity('ff_auth.accounts', {
|
|
111
|
+
allowApiCrud: [FF_Auth_Role.Admin, FF_Role.Admin],
|
|
112
|
+
caption: 'Auth - Accounts',
|
|
113
|
+
// id: { provider: true, userId: true },
|
|
111
114
|
})
|
|
112
|
-
],
|
|
113
|
-
export {
|
|
114
|
-
let
|
|
115
|
+
], FFAuthAccount);
|
|
116
|
+
export { FFAuthAccount };
|
|
117
|
+
let FFAuthUserSession = class FFAuthUserSession {
|
|
115
118
|
id;
|
|
116
119
|
expiresAt;
|
|
117
120
|
userId;
|
|
@@ -119,36 +122,36 @@ let KitAuthUserSession = class KitAuthUserSession {
|
|
|
119
122
|
};
|
|
120
123
|
__decorate([
|
|
121
124
|
Fields.cuid()
|
|
122
|
-
],
|
|
125
|
+
], FFAuthUserSession.prototype, "id", void 0);
|
|
123
126
|
__decorate([
|
|
124
127
|
Fields.date()
|
|
125
|
-
],
|
|
128
|
+
], FFAuthUserSession.prototype, "expiresAt", void 0);
|
|
126
129
|
__decorate([
|
|
127
130
|
Fields.string()
|
|
128
|
-
],
|
|
129
|
-
__decorate([
|
|
130
|
-
Relations.toOne(() =>
|
|
131
|
-
],
|
|
132
|
-
|
|
133
|
-
Entity('
|
|
134
|
-
allowApiCrud: [
|
|
135
|
-
|
|
131
|
+
], FFAuthUserSession.prototype, "userId", void 0);
|
|
132
|
+
__decorate([
|
|
133
|
+
Relations.toOne(() => FFAuthUser, 'userId')
|
|
134
|
+
], FFAuthUserSession.prototype, "user", void 0);
|
|
135
|
+
FFAuthUserSession = __decorate([
|
|
136
|
+
Entity('ff_auth.users_sessions', {
|
|
137
|
+
allowApiCrud: [FF_Auth_Role.Admin, FF_Role.Admin],
|
|
138
|
+
caption: 'Auth - Users sessions',
|
|
136
139
|
})
|
|
137
|
-
],
|
|
138
|
-
export {
|
|
139
|
-
let
|
|
140
|
-
static {
|
|
141
|
-
static DEMO = new
|
|
142
|
-
static PASSWORD = new
|
|
143
|
-
static OTP = new
|
|
144
|
-
static OAUTH = new
|
|
140
|
+
], FFAuthUserSession);
|
|
141
|
+
export { FFAuthUserSession };
|
|
142
|
+
let FFAuthProvider = class FFAuthProvider extends BaseEnum {
|
|
143
|
+
static { FFAuthProvider_1 = this; }
|
|
144
|
+
static DEMO = new FFAuthProvider_1('DEMO', { caption: 'Demo' });
|
|
145
|
+
static PASSWORD = new FFAuthProvider_1('PASSWORD', { caption: 'Password' });
|
|
146
|
+
static OTP = new FFAuthProvider_1('OTP', { caption: 'TOTP' });
|
|
147
|
+
static OAUTH = new FFAuthProvider_1('OAUTH', { caption: 'OAUTH' });
|
|
145
148
|
constructor(id, o) {
|
|
146
149
|
super(id, {
|
|
147
150
|
...o,
|
|
148
151
|
});
|
|
149
152
|
}
|
|
150
153
|
};
|
|
151
|
-
|
|
154
|
+
FFAuthProvider = FFAuthProvider_1 = __decorate([
|
|
152
155
|
ValueListFieldType()
|
|
153
|
-
],
|
|
154
|
-
export {
|
|
156
|
+
], FFAuthProvider);
|
|
157
|
+
export { FFAuthProvider };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Firstly - Module - Auth
|
|
2
|
+
|
|
3
|
+
➡️ Doc available [here](https://firstly.fun/modules/auth).
|
|
4
|
+
|
|
5
|
+
## Complement
|
|
6
|
+
|
|
7
|
+
### Lucia adapter
|
|
8
|
+
|
|
9
|
+
Under the hood, we created a lucia adapter, you can check the code [here](./Adapter.ts) . Feel free
|
|
10
|
+
to copy/paste it in your own codebase. You can also suggest improvements here 😉.
|
|
11
|
+
|
|
12
|
+
By default, all tables/fields will show up in your admin and you are able to extend then with your
|
|
13
|
+
own fields.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ClassType } from 'remult';
|
|
2
2
|
import { Log } from '@kitql/helpers';
|
|
3
|
-
import {
|
|
3
|
+
import { FFAuthUser } from './Entities';
|
|
4
4
|
/**
|
|
5
5
|
* will merge the roles and remove duplicates
|
|
6
6
|
* will return a new array & a status if the array was changed
|
|
@@ -9,6 +9,4 @@ export declare const mergeRoles: (existing: string[], newOnes: string[] | undefi
|
|
|
9
9
|
roles: string[];
|
|
10
10
|
changed: boolean;
|
|
11
11
|
};
|
|
12
|
-
export declare
|
|
13
|
-
static initRoleFromEnv: (log: Log, userEntity: ClassType<KitAuthUser>, envKey: string, role: string) => Promise<void>;
|
|
14
|
-
}
|
|
12
|
+
export declare const initRoleFromEnv: (log: Log, userEntity: ClassType<FFAuthUser>, envValue: string | undefined, role: string) => Promise<void>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { repo } from 'remult';
|
|
2
|
+
import { cyan, green, Log, yellow } from '@kitql/helpers';
|
|
3
|
+
import { FFAuthUser } from './Entities';
|
|
4
|
+
/**
|
|
5
|
+
* will merge the roles and remove duplicates
|
|
6
|
+
* will return a new array & a status if the array was changed
|
|
7
|
+
*/
|
|
8
|
+
export const mergeRoles = (existing, newOnes) => {
|
|
9
|
+
const result = new Set(existing);
|
|
10
|
+
let changed = false;
|
|
11
|
+
for (const role of newOnes ?? []) {
|
|
12
|
+
if (!result.has(role)) {
|
|
13
|
+
result.add(role);
|
|
14
|
+
changed = true;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return { roles: Array.from(result), changed };
|
|
18
|
+
};
|
|
19
|
+
export const initRoleFromEnv = async (log, userEntity, envValue, role) => {
|
|
20
|
+
const names = envValue === undefined ? [] : (envValue ?? '').split(',').map((c) => c.trim());
|
|
21
|
+
for (let i = 0; i < names.length; i++) {
|
|
22
|
+
const name = names[i].trim();
|
|
23
|
+
if (name !== '') {
|
|
24
|
+
let user = await repo(userEntity).findFirst({ name });
|
|
25
|
+
if (!user) {
|
|
26
|
+
user = repo(userEntity).create({ name, roles: [role] });
|
|
27
|
+
await repo(userEntity).save(user);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
if (!user.roles.includes(role)) {
|
|
31
|
+
user.roles.push(role);
|
|
32
|
+
await repo(userEntity).save(user);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (names.length > 0) {
|
|
38
|
+
log.info(`${cyan(role)}: ${names.map((c) => green(c.trim())).join(', ')} added via ${yellow(`.env`)}.`);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
log.info(`${cyan(role)}: No users added via ${yellow(`.env`)}.`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { AuthorizationURLOptions } from '..';
|
|
2
|
+
export declare class Auth {
|
|
3
|
+
static signOutFn: any;
|
|
4
|
+
static signInDemoFn: any;
|
|
5
|
+
static inviteFn: any;
|
|
6
|
+
static signUpPasswordFn: any;
|
|
7
|
+
static signInPasswordFn: any;
|
|
8
|
+
static forgotPasswordFn: any;
|
|
9
|
+
static resetPasswordFn: any;
|
|
10
|
+
static signInOTPFn: any;
|
|
11
|
+
static verifyOtpFn: any;
|
|
12
|
+
static signInOAuthGetUrlFn: any;
|
|
13
|
+
/**
|
|
14
|
+
* Sign out the current user
|
|
15
|
+
*/
|
|
16
|
+
static signOut(): Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* Sign in with a demo account
|
|
19
|
+
* _(The easiest way to demo & test your application)_
|
|
20
|
+
*/
|
|
21
|
+
static signInDemo(name: string): Promise<any>;
|
|
22
|
+
/**
|
|
23
|
+
* This is for login / password authentication SignUp
|
|
24
|
+
* _(The first param `name` can be "anything")_
|
|
25
|
+
*/
|
|
26
|
+
static invite(email: string): Promise<any>;
|
|
27
|
+
/**
|
|
28
|
+
* This is for login / password authentication SignUp
|
|
29
|
+
* _(The first param `email` can be "anything")_
|
|
30
|
+
*/
|
|
31
|
+
static signUpPassword(email: string, password: string): Promise<any>;
|
|
32
|
+
/**
|
|
33
|
+
* This is for login / password authentication SignIn
|
|
34
|
+
* _(The first param `email` can be "anything")_
|
|
35
|
+
*/
|
|
36
|
+
static signInPassword(email: string, password: string): Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Forgot your password ? Send a mail to reset it.
|
|
39
|
+
*/
|
|
40
|
+
static forgotPassword(email: string): Promise<any>;
|
|
41
|
+
/**
|
|
42
|
+
* Reset your password with a token
|
|
43
|
+
*/
|
|
44
|
+
static resetPassword(token: string, password: string): Promise<any>;
|
|
45
|
+
/** OTP */
|
|
46
|
+
static signInOTP(email: string): Promise<any>;
|
|
47
|
+
/**
|
|
48
|
+
* Verify the OTP code
|
|
49
|
+
*/
|
|
50
|
+
static verifyOtp(email: string, otp: string | number): Promise<any>;
|
|
51
|
+
/** OAUTH */
|
|
52
|
+
/**
|
|
53
|
+
* The the url to redirect to for the OAuth provider
|
|
54
|
+
* @param provider Has to mach one of `AUTH_OPTIONS.providers.oAuths` your configured
|
|
55
|
+
*
|
|
56
|
+
* To be used like this for example:
|
|
57
|
+
* ```
|
|
58
|
+
* const url = await Auth.signInOAuthGetUrl('github')
|
|
59
|
+
* window.location.href = url
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* _(popup example should work too, and a nice example/componant would be appreciated)_
|
|
63
|
+
*/
|
|
64
|
+
static signInOAuthGetUrl<T extends keyof AuthorizationURLOptions>(o: {
|
|
65
|
+
provider: T;
|
|
66
|
+
options?: AuthorizationURLOptions[T];
|
|
67
|
+
redirect?: string;
|
|
68
|
+
}): Promise<any>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { BackendMethod } from 'remult';
|
|
8
|
+
export class Auth {
|
|
9
|
+
static signOutFn;
|
|
10
|
+
static signInDemoFn;
|
|
11
|
+
static inviteFn;
|
|
12
|
+
static signUpPasswordFn;
|
|
13
|
+
static signInPasswordFn;
|
|
14
|
+
static forgotPasswordFn;
|
|
15
|
+
static resetPasswordFn;
|
|
16
|
+
static signInOTPFn;
|
|
17
|
+
static verifyOtpFn;
|
|
18
|
+
static signInOAuthGetUrlFn;
|
|
19
|
+
/**
|
|
20
|
+
* Sign out the current user
|
|
21
|
+
*/
|
|
22
|
+
static async signOut() {
|
|
23
|
+
return await Auth.signOutFn();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Sign in with a demo account
|
|
27
|
+
* _(The easiest way to demo & test your application)_
|
|
28
|
+
*/
|
|
29
|
+
static async signInDemo(name) {
|
|
30
|
+
return await Auth.signInDemoFn(name);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* This is for login / password authentication SignUp
|
|
34
|
+
* _(The first param `name` can be "anything")_
|
|
35
|
+
*/
|
|
36
|
+
static async invite(email) {
|
|
37
|
+
return await Auth.inviteFn(email);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* This is for login / password authentication SignUp
|
|
41
|
+
* _(The first param `email` can be "anything")_
|
|
42
|
+
*/
|
|
43
|
+
static async signUpPassword(email, password) {
|
|
44
|
+
return await Auth.signUpPasswordFn(email, password);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* This is for login / password authentication SignIn
|
|
48
|
+
* _(The first param `email` can be "anything")_
|
|
49
|
+
*/
|
|
50
|
+
static async signInPassword(email, password) {
|
|
51
|
+
return await Auth.signInPasswordFn(email, password);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Forgot your password ? Send a mail to reset it.
|
|
55
|
+
*/
|
|
56
|
+
static async forgotPassword(email) {
|
|
57
|
+
return await Auth.forgotPasswordFn(email);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Reset your password with a token
|
|
61
|
+
*/
|
|
62
|
+
static async resetPassword(token, password) {
|
|
63
|
+
return await Auth.resetPasswordFn(token, password);
|
|
64
|
+
}
|
|
65
|
+
/** OTP */
|
|
66
|
+
static async signInOTP(email) {
|
|
67
|
+
return await Auth.signInOTPFn(email);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Verify the OTP code
|
|
71
|
+
*/
|
|
72
|
+
static async verifyOtp(email, otp) {
|
|
73
|
+
return await Auth.verifyOtpFn(email, otp);
|
|
74
|
+
}
|
|
75
|
+
/** OAUTH */
|
|
76
|
+
/**
|
|
77
|
+
* The the url to redirect to for the OAuth provider
|
|
78
|
+
* @param provider Has to mach one of `AUTH_OPTIONS.providers.oAuths` your configured
|
|
79
|
+
*
|
|
80
|
+
* To be used like this for example:
|
|
81
|
+
* ```
|
|
82
|
+
* const url = await Auth.signInOAuthGetUrl('github')
|
|
83
|
+
* window.location.href = url
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* _(popup example should work too, and a nice example/componant would be appreciated)_
|
|
87
|
+
*/
|
|
88
|
+
static async signInOAuthGetUrl(o) {
|
|
89
|
+
return await Auth.signInOAuthGetUrlFn(o);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
__decorate([
|
|
93
|
+
BackendMethod({ allowed: true })
|
|
94
|
+
], Auth, "signOut", null);
|
|
95
|
+
__decorate([
|
|
96
|
+
BackendMethod({ allowed: true })
|
|
97
|
+
], Auth, "signInDemo", null);
|
|
98
|
+
__decorate([
|
|
99
|
+
BackendMethod({ allowed: false })
|
|
100
|
+
], Auth, "invite", null);
|
|
101
|
+
__decorate([
|
|
102
|
+
BackendMethod({ allowed: true })
|
|
103
|
+
], Auth, "signUpPassword", null);
|
|
104
|
+
__decorate([
|
|
105
|
+
BackendMethod({ allowed: true })
|
|
106
|
+
], Auth, "signInPassword", null);
|
|
107
|
+
__decorate([
|
|
108
|
+
BackendMethod({ allowed: true })
|
|
109
|
+
], Auth, "forgotPassword", null);
|
|
110
|
+
__decorate([
|
|
111
|
+
BackendMethod({ allowed: true })
|
|
112
|
+
], Auth, "resetPassword", null);
|
|
113
|
+
__decorate([
|
|
114
|
+
BackendMethod({ allowed: true })
|
|
115
|
+
], Auth, "signInOTP", null);
|
|
116
|
+
__decorate([
|
|
117
|
+
BackendMethod({ allowed: true })
|
|
118
|
+
], Auth, "verifyOtp", null);
|
|
119
|
+
__decorate([
|
|
120
|
+
BackendMethod({ allowed: true })
|
|
121
|
+
], Auth, "signInOAuthGetUrl", null);
|
package/esm/auth/index.d.ts
CHANGED
|
@@ -4,33 +4,32 @@ import type { ClassType, UserInfo } from 'remult';
|
|
|
4
4
|
import { Log } from '@kitql/helpers';
|
|
5
5
|
import type { Module } from '../api';
|
|
6
6
|
import type { ResolvedType } from '../utils/types';
|
|
7
|
-
import {
|
|
7
|
+
import { FFAuthAccount, FFAuthProvider, FFAuthUser, FFAuthUserSession } from './Entities';
|
|
8
8
|
import type { firstlyData } from './types';
|
|
9
9
|
export type { firstlyData };
|
|
10
|
-
export {
|
|
11
|
-
export { AuthController } from './AuthController';
|
|
10
|
+
export { FFAuthUser, FFAuthAccount, FFAuthProvider, FFAuthUserSession };
|
|
12
11
|
export type AuthorizationURLOptions = Record<string, {
|
|
13
12
|
scopes?: string[];
|
|
14
13
|
}>;
|
|
15
|
-
export type DynamicAuthorizationURLOptions<T extends
|
|
14
|
+
export type DynamicAuthorizationURLOptions<T extends FFOAuth2Provider[] = FFOAuth2Provider[]> = T extends Array<infer O> ? O extends FFOAuth2Provider ? {
|
|
16
15
|
[P in O['name']]: ReturnType<O['authorizationURLOptions']>;
|
|
17
16
|
} : never : never;
|
|
18
17
|
export declare const logAuth: Log;
|
|
19
|
-
export {
|
|
18
|
+
export { FF_Auth_Role } from './Entities';
|
|
20
19
|
type OAuth2UserInfo = {
|
|
21
20
|
raw?: any;
|
|
22
21
|
providerUserId: string;
|
|
23
22
|
/** Will take the first option available */
|
|
24
23
|
nameOptions: string[];
|
|
25
24
|
};
|
|
26
|
-
export type
|
|
25
|
+
export type FFOAuth2Provider<LitName extends string = string, T extends ArcticOAuth2Provider | ArcticOAuth2ProviderWithPKCE = ArcticOAuth2Provider> = {
|
|
27
26
|
name: LitName;
|
|
28
27
|
getArcticProvider: () => T;
|
|
29
28
|
isPKCE: T extends ArcticOAuth2Provider ? false : T extends ArcticOAuth2ProviderWithPKCE ? true : never;
|
|
30
29
|
authorizationURLOptions: () => T extends ArcticOAuth2Provider ? Parameters<T['createAuthorizationURL']>[1] : T extends ArcticOAuth2ProviderWithPKCE ? Parameters<T['createAuthorizationURL']>[2] : never;
|
|
31
30
|
getUserInfo(tokens: ResolvedType<ReturnType<T['validateAuthorizationCode']>>): Promise<OAuth2UserInfo>;
|
|
32
31
|
};
|
|
33
|
-
type AuthOptions<TUserEntity extends
|
|
32
|
+
type AuthOptions<TUserEntity extends FFAuthUser = FFAuthUser, TSessionEntity extends FFAuthUserSession = FFAuthUserSession, TAccountEntity extends FFAuthAccount = FFAuthAccount> = {
|
|
34
33
|
customEntities?: {
|
|
35
34
|
User?: ClassType<TUserEntity>;
|
|
36
35
|
Session?: ClassType<TSessionEntity>;
|
|
@@ -112,14 +111,14 @@ type AuthOptions<TUserEntity extends KitAuthUser = KitAuthUser, TSessionEntity e
|
|
|
112
111
|
uri: string;
|
|
113
112
|
}) => Promise<void>;
|
|
114
113
|
};
|
|
115
|
-
oAuths?:
|
|
114
|
+
oAuths?: FFOAuth2Provider[];
|
|
116
115
|
};
|
|
117
116
|
};
|
|
118
117
|
export declare let AUTH_OPTIONS: AuthOptions;
|
|
119
118
|
export declare const getSafeOptions: () => {
|
|
120
|
-
User: ClassType<
|
|
121
|
-
Session: ClassType<
|
|
122
|
-
Account: ClassType<
|
|
119
|
+
User: ClassType<FFAuthUser>;
|
|
120
|
+
Session: ClassType<FFAuthUserSession>;
|
|
121
|
+
Account: ClassType<FFAuthAccount>;
|
|
123
122
|
signUp: boolean;
|
|
124
123
|
password_enabled: boolean;
|
|
125
124
|
otp_enabled: boolean;
|