firstly 0.2.1 → 0.4.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/CHANGELOG.md +65 -0
- package/esm/SqlDatabase/FF_LogToConsole.js +9 -14
- package/esm/carbone/CarboneController.js +2 -1
- package/esm/changeLog/index.d.ts +0 -10
- package/esm/{internals → core}/BaseEnum.d.ts +1 -1
- package/esm/core/FF_Entity.js +5 -0
- package/esm/core/helper.d.ts +2 -0
- package/esm/core/helper.js +3 -0
- package/esm/core/index.d.ts +0 -0
- package/esm/core/index.js +5 -0
- package/esm/core/tailwind.d.ts +21 -0
- package/esm/core/tailwind.js +22 -0
- package/esm/core/tryCatch.d.ts +44 -0
- package/esm/core/tryCatch.js +34 -0
- package/esm/cron/server/index.js +1 -1
- package/esm/feedback/FeedbackController.js +3 -2
- package/esm/feedback/index.d.ts +7 -2
- package/esm/feedback/index.js +1 -2
- package/esm/feedback/server/index.d.ts +0 -5
- package/esm/feedback/server/index.js +1 -1
- package/esm/formats/strings.js +2 -2
- package/esm/index.d.ts +16 -0
- package/esm/index.js +13 -0
- package/esm/svelte/FF_Repo.svelte.d.ts +9 -2
- package/esm/svelte/FF_Repo.svelte.js +40 -17
- package/esm/svelte/class/SP.svelte.js +14 -2
- package/esm/svelte/helpers/debounce.js +1 -1
- package/esm/svelte/index.d.ts +2 -24
- package/esm/svelte/index.js +2 -22
- package/esm/{ui → svelte/ui}/Icon.svelte +1 -1
- package/esm/virtual/StateDemoEnum.d.ts +3 -3
- package/esm/virtual/StateDemoEnum.js +3 -3
- package/esm/virtual/UIEntity.js +1 -2
- package/package.json +8 -39
- package/esm/auth/AuthController.d.ts +0 -58
- package/esm/auth/AuthController.js +0 -114
- package/esm/auth/Entities.d.ts +0 -47
- package/esm/auth/Entities.js +0 -182
- package/esm/auth/README.md +0 -3
- package/esm/auth/index.d.ts +0 -5
- package/esm/auth/index.js +0 -5
- package/esm/auth/server/AuthController.server.d.ts +0 -58
- package/esm/auth/server/AuthController.server.js +0 -518
- package/esm/auth/server/handleAuth.d.ts +0 -4
- package/esm/auth/server/handleAuth.js +0 -142
- package/esm/auth/server/handleGuard.d.ts +0 -22
- package/esm/auth/server/handleGuard.js +0 -34
- package/esm/auth/server/helperDb.d.ts +0 -10
- package/esm/auth/server/helperDb.js +0 -56
- package/esm/auth/server/helperFirstly.d.ts +0 -1
- package/esm/auth/server/helperFirstly.js +0 -9
- package/esm/auth/server/helperOslo.d.ts +0 -7
- package/esm/auth/server/helperOslo.js +0 -24
- package/esm/auth/server/helperRemultServer.d.ts +0 -5
- package/esm/auth/server/helperRemultServer.js +0 -44
- package/esm/auth/server/helperRole.d.ts +0 -19
- package/esm/auth/server/helperRole.js +0 -57
- package/esm/auth/server/index.d.ts +0 -8
- package/esm/auth/server/index.js +0 -8
- package/esm/auth/server/module.d.ts +0 -300
- package/esm/auth/server/module.js +0 -230
- package/esm/auth/server/providers/github.d.ts +0 -33
- package/esm/auth/server/providers/github.js +0 -87
- package/esm/auth/server/providers/helperProvider.d.ts +0 -1
- package/esm/auth/server/providers/helperProvider.js +0 -25
- package/esm/auth/static/assets/Page-BHW08QWz.css +0 -1
- package/esm/auth/static/assets/Page-BRNWcY5Z.d.ts +0 -2
- package/esm/auth/static/assets/Page-BRNWcY5Z.js +0 -1
- package/esm/auth/static/assets/Page-CFcEsGK8.d.ts +0 -2
- package/esm/auth/static/assets/Page-CFcEsGK8.js +0 -7
- package/esm/auth/static/assets/Page-tLVs5slF.d.ts +0 -2
- package/esm/auth/static/assets/Page-tLVs5slF.js +0 -1
- package/esm/auth/static/assets/index-D38rqu4x.d.ts +0 -201
- package/esm/auth/static/assets/index-D38rqu4x.js +0 -2
- package/esm/auth/static/assets/index-DKWpA6v7.css +0 -4
- package/esm/auth/static/favicon.svg +0 -79
- package/esm/auth/static/index.html +0 -13
- package/esm/auth/types.d.ts +0 -73
- package/esm/bin/cmd.d.ts +0 -1
- package/esm/bin/cmd.js +0 -793
- package/esm/feedback/ui/DialogIssue.svelte +0 -149
- package/esm/feedback/ui/DialogIssue.svelte.d.ts +0 -22
- package/esm/feedback/ui/DialogIssues.svelte +0 -114
- package/esm/feedback/ui/DialogIssues.svelte.d.ts +0 -22
- package/esm/feedback/ui/DialogMilestones.svelte +0 -43
- package/esm/feedback/ui/DialogMilestones.svelte.d.ts +0 -20
- package/esm/feedback/ui/Feedback.svelte +0 -16
- package/esm/feedback/ui/Feedback.svelte.d.ts +0 -18
- package/esm/internals/FF_Entity.d.ts +0 -2
- package/esm/internals/FF_Entity.js +0 -21
- package/esm/internals/FF_Fields.d.ts +0 -11
- package/esm/internals/FF_Fields.js +0 -144
- package/esm/internals/cellsBuildor.d.ts +0 -47
- package/esm/internals/cellsBuildor.js +0 -140
- package/esm/internals/helper.d.ts +0 -49
- package/esm/internals/helper.js +0 -162
- package/esm/internals/index.d.ts +0 -82
- package/esm/internals/index.js +0 -45
- package/esm/internals/storeItem.d.ts +0 -28
- package/esm/internals/storeItem.js +0 -176
- package/esm/internals/storeList.d.ts +0 -34
- package/esm/internals/storeList.js +0 -108
- package/esm/internals/theme.d.ts +0 -4
- package/esm/internals/theme.js +0 -4
- package/esm/server/index.d.ts +0 -52
- package/esm/server/index.js +0 -87
- package/esm/svelte/FF_Cell.svelte +0 -103
- package/esm/svelte/FF_Cell.svelte.d.ts +0 -33
- package/esm/svelte/FF_Cell_Caption.svelte +0 -20
- package/esm/svelte/FF_Cell_Caption.svelte.d.ts +0 -31
- package/esm/svelte/FF_Cell_Display.svelte +0 -61
- package/esm/svelte/FF_Cell_Display.svelte.d.ts +0 -29
- package/esm/svelte/FF_Cell_Edit.svelte +0 -104
- package/esm/svelte/FF_Cell_Edit.svelte.d.ts +0 -32
- package/esm/svelte/FF_Cell_Error.svelte +0 -20
- package/esm/svelte/FF_Cell_Error.svelte.d.ts +0 -31
- package/esm/svelte/FF_Cell_Hint.svelte +0 -20
- package/esm/svelte/FF_Cell_Hint.svelte.d.ts +0 -31
- package/esm/svelte/FF_Config.svelte +0 -29
- package/esm/svelte/FF_Config.svelte.d.ts +0 -9
- package/esm/svelte/FF_Form.svelte +0 -155
- package/esm/svelte/FF_Form.svelte.d.ts +0 -37
- package/esm/svelte/FF_Grid.svelte +0 -257
- package/esm/svelte/FF_Grid.svelte.d.ts +0 -37
- package/esm/svelte/FF_Layout.svelte +0 -62
- package/esm/svelte/FF_Layout.svelte.d.ts +0 -31
- package/esm/svelte/actions/intersection.d.ts +0 -6
- package/esm/svelte/actions/intersection.js +0 -17
- package/esm/svelte/customField.d.ts +0 -69
- package/esm/svelte/customField.js +0 -4
- package/esm/svelte/dialog/DialogManagement.svelte +0 -98
- package/esm/svelte/dialog/DialogManagement.svelte.d.ts +0 -18
- package/esm/svelte/dialog/DialogPrimitive.svelte +0 -156
- package/esm/svelte/dialog/DialogPrimitive.svelte.d.ts +0 -38
- package/esm/svelte/dialog/dialog.d.ts +0 -58
- package/esm/svelte/dialog/dialog.js +0 -130
- package/esm/svelte/ff_Config.svelte.d.ts +0 -91
- package/esm/svelte/ff_Config.svelte.js +0 -111
- package/esm/svelte/firstly.css +0 -14
- package/esm/svelte/helpers.d.ts +0 -30
- package/esm/svelte/helpers.js +0 -38
- package/esm/svelte/tryCatch.d.ts +0 -12
- package/esm/svelte/tryCatch.js +0 -18
- package/esm/sveltekit/server/index.d.ts +0 -5
- package/esm/sveltekit/server/index.js +0 -24
- package/esm/ui/Button.svelte +0 -138
- package/esm/ui/Button.svelte.d.ts +0 -13
- package/esm/ui/Clipboardable.svelte +0 -25
- package/esm/ui/Clipboardable.svelte.d.ts +0 -12
- package/esm/ui/Field.svelte +0 -382
- package/esm/ui/Field.svelte.d.ts +0 -40
- package/esm/ui/FieldGroup.svelte +0 -117
- package/esm/ui/FieldGroup.svelte.d.ts +0 -44
- package/esm/ui/Grid.svelte +0 -265
- package/esm/ui/Grid.svelte.d.ts +0 -57
- package/esm/ui/Grid2.svelte +0 -293
- package/esm/ui/Grid2.svelte.d.ts +0 -57
- package/esm/ui/GridLoading.svelte +0 -58
- package/esm/ui/GridLoading.svelte.d.ts +0 -23
- package/esm/ui/GridPaginate.svelte +0 -69
- package/esm/ui/GridPaginate.svelte.d.ts +0 -23
- package/esm/ui/GridPaginate2.svelte +0 -25
- package/esm/ui/GridPaginate2.svelte.d.ts +0 -7
- package/esm/ui/Loading.svelte +0 -16
- package/esm/ui/Loading.svelte.d.ts +0 -31
- package/esm/ui/Tooltip.svelte +0 -45
- package/esm/ui/Tooltip.svelte.d.ts +0 -32
- package/esm/ui/dialog/DialogForm.svelte +0 -76
- package/esm/ui/dialog/DialogForm.svelte.d.ts +0 -21
- package/esm/ui/dialog/DialogManagement.svelte +0 -96
- package/esm/ui/dialog/DialogManagement.svelte.d.ts +0 -26
- package/esm/ui/dialog/DialogPrimitive.svelte +0 -90
- package/esm/ui/dialog/DialogPrimitive.svelte.d.ts +0 -38
- package/esm/ui/dialog/FormEditAction.svelte +0 -62
- package/esm/ui/dialog/FormEditAction.svelte.d.ts +0 -31
- package/esm/ui/dialog/dialog.d.ts +0 -60
- package/esm/ui/dialog/dialog.js +0 -100
- package/esm/ui/index.d.ts +0 -6
- package/esm/ui/index.js +0 -20
- package/esm/ui/internals/FieldContainer.svelte +0 -39
- package/esm/ui/internals/FieldContainer.svelte.d.ts +0 -18
- package/esm/ui/internals/Input.svelte +0 -143
- package/esm/ui/internals/Input.svelte.d.ts +0 -37
- package/esm/ui/internals/Textarea.svelte +0 -66
- package/esm/ui/internals/Textarea.svelte.d.ts +0 -33
- package/esm/ui/internals/select/MultiSelectMelt.svelte +0 -260
- package/esm/ui/internals/select/MultiSelectMelt.svelte.d.ts +0 -32
- package/esm/ui/internals/select/Select2.svelte +0 -88
- package/esm/ui/internals/select/Select2.svelte.d.ts +0 -12
- package/esm/ui/internals/select/SelectMelt.svelte +0 -280
- package/esm/ui/internals/select/SelectMelt.svelte.d.ts +0 -40
- package/esm/ui/internals/select/SelectRadio.svelte +0 -43
- package/esm/ui/internals/select/SelectRadio.svelte.d.ts +0 -27
- package/esm/ui/link/Link.svelte +0 -33
- package/esm/ui/link/Link.svelte.d.ts +0 -33
- package/esm/ui/link/LinkPlus.svelte +0 -63
- package/esm/ui/link/LinkPlus.svelte.d.ts +0 -9
- package/esm/utils/tailwind.d.ts +0 -2
- package/esm/utils/tailwind.js +0 -3
- package/esm/utils/transition.d.ts +0 -9
- package/esm/utils/transition.js +0 -33
- package/esm/utils/types.js +0 -1
- /package/esm/{internals → core}/BaseEnum.js +0 -0
- /package/esm/{internals → core}/common.d.ts +0 -0
- /package/esm/{internals → core}/common.js +0 -0
- /package/esm/{utils → core}/types.d.ts +0 -0
- /package/esm/{auth → core}/types.js +0 -0
- /package/esm/{ui → svelte/ui}/Icon.svelte.d.ts +0 -0
- /package/esm/{ui → svelte/ui}/LibIcon.d.ts +0 -0
- /package/esm/{ui → svelte/ui}/LibIcon.js +0 -0
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import bcrypt from 'bcryptjs';
|
|
2
|
-
import { EntityError, remult } from 'remult';
|
|
3
|
-
import { red, yellow } from '@kitql/helpers';
|
|
4
|
-
import { getRelativePackagePath } from '@kitql/internals';
|
|
5
|
-
import { env } from '$env/dynamic/private';
|
|
6
|
-
import { building } from '$app/environment';
|
|
7
|
-
import { AuthController } from '..';
|
|
8
|
-
import { ModuleFF } from '../../server';
|
|
9
|
-
import { FFAuthAccount, FFAuthUser, FFAuthUserSession } from '../Entities';
|
|
10
|
-
import { AuthControllerServer } from './AuthController.server';
|
|
11
|
-
import { validateSessionToken } from './helperDb';
|
|
12
|
-
import { setSessionTokenCookie } from './helperRemultServer';
|
|
13
|
-
import { linkRoleToUsersFromEnv } from './helperRole';
|
|
14
|
-
export let AUTH_OPTIONS = { ui: {} };
|
|
15
|
-
const buildUrlOrDefault = (base, userSetting, fallback) => {
|
|
16
|
-
if (userSetting === false) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
if (userSetting === undefined) {
|
|
20
|
-
return `${base}/${fallback}`;
|
|
21
|
-
}
|
|
22
|
-
return `${base}/${userSetting}`;
|
|
23
|
-
};
|
|
24
|
-
export const getSafeOptions = () => {
|
|
25
|
-
const signUp = AUTH_OPTIONS.signUp ?? true;
|
|
26
|
-
const base = AUTH_OPTIONS.ui === false ? 'NO_BASE_PATH' : (AUTH_OPTIONS.ui?.paths?.base ?? '/ff/auth');
|
|
27
|
-
const ui = AUTH_OPTIONS.ui === false
|
|
28
|
-
? undefined
|
|
29
|
-
: {
|
|
30
|
-
paths: {
|
|
31
|
-
base,
|
|
32
|
-
sign_up: signUp ? buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.sign_up, 'sign-up') : false,
|
|
33
|
-
sign_in: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.sign_in, 'sign-in'),
|
|
34
|
-
forgot_password: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.forgot_password, 'forgot-password'),
|
|
35
|
-
reset_password: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.reset_password, 'reset-password'),
|
|
36
|
-
verify_email: buildUrlOrDefault(base, AUTH_OPTIONS.ui?.paths?.verify_email, 'verify-email'),
|
|
37
|
-
},
|
|
38
|
-
strings: {
|
|
39
|
-
app_name: AUTH_OPTIONS.ui?.strings?.app_name ?? '',
|
|
40
|
-
email: AUTH_OPTIONS.ui?.strings?.email ?? 'Email',
|
|
41
|
-
email_placeholder: AUTH_OPTIONS.ui?.strings?.email_placeholder ?? 'Your email address',
|
|
42
|
-
password: AUTH_OPTIONS.ui?.strings?.password ?? 'Password',
|
|
43
|
-
password_placeholder: AUTH_OPTIONS.ui?.strings?.password_placeholder ?? 'Your password',
|
|
44
|
-
confirm: AUTH_OPTIONS.ui?.strings?.confirm ?? 'Confirm',
|
|
45
|
-
reset: AUTH_OPTIONS.ui?.strings?.reset ?? 'Reset',
|
|
46
|
-
btn_sign_up: AUTH_OPTIONS.ui?.strings?.btn_sign_up ?? 'Sign up',
|
|
47
|
-
btn_sign_in: AUTH_OPTIONS.ui?.strings?.btn_sign_in ?? 'Sign in',
|
|
48
|
-
forgot_password: AUTH_OPTIONS.ui?.strings?.forgot_password ?? 'Forgot your password?',
|
|
49
|
-
send_password_reset_instructions: AUTH_OPTIONS.ui?.strings?.send_password_reset_instructions ??
|
|
50
|
-
'Send password reset instructions',
|
|
51
|
-
back_to_sign_in: AUTH_OPTIONS.ui?.strings?.back_to_sign_in ?? 'Back to sign in',
|
|
52
|
-
},
|
|
53
|
-
images: {
|
|
54
|
-
main: AUTH_OPTIONS.ui?.images?.main ?? '',
|
|
55
|
-
},
|
|
56
|
-
customHtmlHead: AUTH_OPTIONS.ui?.customHtmlHead ??
|
|
57
|
-
'<title>Auth</title><link rel="icon" href="https://firstly.fun/favicon.svg" />',
|
|
58
|
-
};
|
|
59
|
-
if (AUTH_OPTIONS.debug && !building) {
|
|
60
|
-
authModuleRaw.log.info('ui', ui);
|
|
61
|
-
}
|
|
62
|
-
const getProviderIcon = (name) => {
|
|
63
|
-
switch (name) {
|
|
64
|
-
case 'github':
|
|
65
|
-
return `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg>`;
|
|
66
|
-
case 'google':
|
|
67
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"><!-- Icon from Devicon by konpa - https://github.com/devicons/devicon/blob/master/LICENSE --><path fill="#fff" d="M44.59 4.21a63.28 63.28 0 0 0 4.33 120.9a67.6 67.6 0 0 0 32.36.35a57.13 57.13 0 0 0 25.9-13.46a57.44 57.44 0 0 0 16-26.26a74.3 74.3 0 0 0 1.61-33.58H65.27v24.69h34.47a29.72 29.72 0 0 1-12.66 19.52a36.2 36.2 0 0 1-13.93 5.5a41.3 41.3 0 0 1-15.1 0A37.2 37.2 0 0 1 44 95.74a39.3 39.3 0 0 1-14.5-19.42a38.3 38.3 0 0 1 0-24.63a39.25 39.25 0 0 1 9.18-14.91A37.17 37.17 0 0 1 76.13 27a34.3 34.3 0 0 1 13.64 8q5.83-5.8 11.64-11.63c2-2.09 4.18-4.08 6.15-6.22A61.2 61.2 0 0 0 87.2 4.59a64 64 0 0 0-42.61-.38"/><path fill="#e33629" d="M44.59 4.21a64 64 0 0 1 42.61.37a61.2 61.2 0 0 1 20.35 12.62c-2 2.14-4.11 4.14-6.15 6.22Q95.58 29.23 89.77 35a34.3 34.3 0 0 0-13.64-8a37.17 37.17 0 0 0-37.46 9.74a39.25 39.25 0 0 0-9.18 14.91L8.76 35.6A63.53 63.53 0 0 1 44.59 4.21"/><path fill="#f8bd00" d="M3.26 51.5a63 63 0 0 1 5.5-15.9l20.73 16.09a38.3 38.3 0 0 0 0 24.63q-10.36 8-20.73 16.08a63.33 63.33 0 0 1-5.5-40.9"/><path fill="#587dbd" d="M65.27 52.15h59.52a74.3 74.3 0 0 1-1.61 33.58a57.44 57.44 0 0 1-16 26.26c-6.69-5.22-13.41-10.4-20.1-15.62a29.72 29.72 0 0 0 12.66-19.54H65.27c-.01-8.22 0-16.45 0-24.68"/><path fill="#319f43" d="M8.75 92.4q10.37-8 20.73-16.08A39.3 39.3 0 0 0 44 95.74a37.2 37.2 0 0 0 14.08 6.08a41.3 41.3 0 0 0 15.1 0a36.2 36.2 0 0 0 13.93-5.5c6.69 5.22 13.41 10.4 20.1 15.62a57.13 57.13 0 0 1-25.9 13.47a67.6 67.6 0 0 1-32.36-.35a63 63 0 0 1-23-11.59A63.7 63.7 0 0 1 8.75 92.4"/></svg>`;
|
|
68
|
-
default:
|
|
69
|
-
return '';
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
const providers = AUTH_OPTIONS.providers?.oAuths?.map((o) => ({
|
|
73
|
-
name: o.name,
|
|
74
|
-
label: o.caption,
|
|
75
|
-
raw_svg: o.raw_svg ?? getProviderIcon(o.name),
|
|
76
|
-
})) ?? [];
|
|
77
|
-
const firstlyData = {
|
|
78
|
-
module: 'auth',
|
|
79
|
-
debug: AUTH_OPTIONS.debug,
|
|
80
|
-
props: {
|
|
81
|
-
ui,
|
|
82
|
-
providers,
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
let uiStaticPath = AUTH_OPTIONS.uiStaticPath ?? '';
|
|
86
|
-
if (!AUTH_OPTIONS.uiStaticPath) {
|
|
87
|
-
const installedFirstlyPath = getRelativePackagePath('firstly');
|
|
88
|
-
if (installedFirstlyPath) {
|
|
89
|
-
uiStaticPath = `${installedFirstlyPath}/esm/auth/static/`;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
let redirectUrl = AUTH_OPTIONS.defaultRedirect ?? '/';
|
|
93
|
-
if (!redirectUrl.startsWith('/')) {
|
|
94
|
-
authModuleRaw.log.error(`Invalid redirect url ${red(redirectUrl)} (it should be a local one starting with /)`);
|
|
95
|
-
redirectUrl = '/';
|
|
96
|
-
}
|
|
97
|
-
let transformDbUserToClientUserToUse;
|
|
98
|
-
if (AUTH_OPTIONS.transformDbUserToClientUser) {
|
|
99
|
-
transformDbUserToClientUserToUse = AUTH_OPTIONS.transformDbUserToClientUser;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
// @ts-ignore (I'm not sure why cadb-my-doc is failing check here if I don't do this!)
|
|
103
|
-
transformDbUserToClientUserToUse = (session, user) => {
|
|
104
|
-
return {
|
|
105
|
-
id: user.id,
|
|
106
|
-
name: user.name,
|
|
107
|
-
roles: user.roles,
|
|
108
|
-
session: {
|
|
109
|
-
id: session.id,
|
|
110
|
-
expiresAt: session.expiresAt,
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
function validateInput({ identifier, password }) {
|
|
116
|
-
if (typeof identifier !== 'string' || identifier.length === 0) {
|
|
117
|
-
throw new EntityError({ message: 'Invalid identifier' });
|
|
118
|
-
}
|
|
119
|
-
if (typeof password !== 'string') {
|
|
120
|
-
throw new EntityError({ message: 'Invalid password' });
|
|
121
|
-
}
|
|
122
|
-
if (password.length < 6 || password.length > 255) {
|
|
123
|
-
throw new EntityError({ message: 'Password too short or too long!' });
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
function passwordHash(password) {
|
|
127
|
-
return bcrypt.hashSync(password, AUTH_OPTIONS.providers?.password?.algo?.bcrypt?.saltRounds ?? 10);
|
|
128
|
-
}
|
|
129
|
-
function passwordVerify(password, hash) {
|
|
130
|
-
return bcrypt.compareSync(password, hash);
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
User: (AUTH_OPTIONS.customEntities?.User ?? FFAuthUser),
|
|
134
|
-
Session: (AUTH_OPTIONS.customEntities?.Session ?? FFAuthUserSession),
|
|
135
|
-
Account: (AUTH_OPTIONS.customEntities?.Account ?? FFAuthAccount),
|
|
136
|
-
signUp,
|
|
137
|
-
password: {
|
|
138
|
-
enabled: AUTH_OPTIONS.providers?.password ? true : false,
|
|
139
|
-
validateInput: AUTH_OPTIONS.providers?.password?.algo?.validateInput ?? validateInput,
|
|
140
|
-
hash: AUTH_OPTIONS.providers?.password?.algo?.hash ?? passwordHash,
|
|
141
|
-
verify: AUTH_OPTIONS.providers?.password?.algo?.verify ?? passwordVerify,
|
|
142
|
-
},
|
|
143
|
-
otp: { enabled: AUTH_OPTIONS.providers?.otp ? true : false },
|
|
144
|
-
verifiedMethod: AUTH_OPTIONS.verifiedMethod ?? 'auto',
|
|
145
|
-
redirectUrl,
|
|
146
|
-
firstlyData,
|
|
147
|
-
transformDbUserToClientUser: transformDbUserToClientUserToUse,
|
|
148
|
-
uiStaticPath,
|
|
149
|
-
session: {
|
|
150
|
-
expiresInMs: AUTH_OPTIONS.session?.expiresIn ?? 1000 * 60 * 60 * 24 * 30, // 30 days,
|
|
151
|
-
cookieName: AUTH_OPTIONS.session?.COOKIE_NAME ?? 'firstly_auth_session',
|
|
152
|
-
},
|
|
153
|
-
providers: AUTH_OPTIONS.providers,
|
|
154
|
-
strings: {
|
|
155
|
-
resetPasswordSend: AUTH_OPTIONS.strings?.resetPasswordSend ?? 'Mail sent ! You can now close this window.',
|
|
156
|
-
resetPasswordUnknownUser: AUTH_OPTIONS.strings?.resetPasswordUnknownUser ??
|
|
157
|
-
'If your email is registered, you will receive an email with a link to reset your password.',
|
|
158
|
-
anErrorOccurred: AUTH_OPTIONS.strings?.anErrorOccurred ?? 'An error occurred, contact the administrator.',
|
|
159
|
-
cannotSignUp: AUTH_OPTIONS.strings?.cannotSignUp ??
|
|
160
|
-
"You can't signup by yourself! Contact the administrator.",
|
|
161
|
-
},
|
|
162
|
-
ui,
|
|
163
|
-
envRoles_AssignUsers: AUTH_OPTIONS.envRoles_AssignUsers ?? {},
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
export const authModuleRaw = new ModuleFF({
|
|
167
|
-
name: 'auth',
|
|
168
|
-
priority: -777,
|
|
169
|
-
});
|
|
170
|
-
/**
|
|
171
|
-
* To enable authentication in your app in a few lines of code.
|
|
172
|
-
* _Info: index: -777_
|
|
173
|
-
*/
|
|
174
|
-
export const auth = (o) => {
|
|
175
|
-
// TODO should work ?
|
|
176
|
-
// @ts-ignore
|
|
177
|
-
AUTH_OPTIONS = o;
|
|
178
|
-
const oSafe = getSafeOptions();
|
|
179
|
-
// Replace the direct assignments with the new _setImplementation method
|
|
180
|
-
AuthController._setAbstraction({
|
|
181
|
-
signOut: AuthControllerServer.signOut,
|
|
182
|
-
signInDemo: AuthControllerServer.signInDemo,
|
|
183
|
-
invite: AuthControllerServer.invite,
|
|
184
|
-
signUpPassword: AuthControllerServer.signUpPassword,
|
|
185
|
-
signInPassword: AuthControllerServer.signInPassword,
|
|
186
|
-
forgotPassword: AuthControllerServer.forgotPassword,
|
|
187
|
-
resetPassword: AuthControllerServer.resetPassword,
|
|
188
|
-
signInOTP: AuthControllerServer.signInOTP,
|
|
189
|
-
verifyOtp: AuthControllerServer.verifyOtp,
|
|
190
|
-
signInOAuthGetUrl: AuthControllerServer.signInOAuthGetUrl,
|
|
191
|
-
});
|
|
192
|
-
authModuleRaw.entities = [oSafe.User, oSafe.Session, oSafe.Account];
|
|
193
|
-
authModuleRaw.controllers = [AuthController];
|
|
194
|
-
authModuleRaw.initRequest = async (event) => {
|
|
195
|
-
// REMULT: storing user in local should probably be done in remult directly
|
|
196
|
-
if (event?.locals?.user) {
|
|
197
|
-
remult.user = event.locals.user;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
const sessionId = event.cookies.get(oSafe.session.cookieName);
|
|
201
|
-
if (sessionId) {
|
|
202
|
-
const { user, freshSession } = await validateSessionToken(sessionId);
|
|
203
|
-
if (freshSession) {
|
|
204
|
-
setSessionTokenCookie(freshSession.sessionToken, freshSession.expiresAt);
|
|
205
|
-
}
|
|
206
|
-
remult.user = user;
|
|
207
|
-
if (event.locals) {
|
|
208
|
-
event.locals.user = user;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
authModuleRaw.initApi = async () => {
|
|
214
|
-
const oSafe = getSafeOptions();
|
|
215
|
-
for (const [key, value] of Object.entries(oSafe.envRoles_AssignUsers)) {
|
|
216
|
-
await linkRoleToUsersFromEnv({
|
|
217
|
-
log: authModuleRaw.log,
|
|
218
|
-
accountEntity: oSafe.Account,
|
|
219
|
-
userEntity: oSafe.User,
|
|
220
|
-
envKey: key.toUpperCase(),
|
|
221
|
-
envValue: env[key.toUpperCase()] ?? '',
|
|
222
|
-
roles: [value],
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
if (Object.entries(oSafe.envRoles_AssignUsers).length === 0 && AUTH_OPTIONS.debug) {
|
|
226
|
-
authModuleRaw.log.info(`set ${yellow('auth: { linkRoleToUsersFromEnv: ... }')} to assign roles to users via ${yellow('.env')}.`);
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
return authModuleRaw;
|
|
230
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { OAuth2Tokens } from 'arctic';
|
|
2
|
-
import { GitHub } from 'arctic';
|
|
3
|
-
import type { OAuth2UserInfo, ProviderAuthorizationURLOptions } from '../../types';
|
|
4
|
-
import { type FFOAuth2Provider } from '../module';
|
|
5
|
-
/**
|
|
6
|
-
* ## GitHub OAuth2 provider
|
|
7
|
-
*
|
|
8
|
-
* 1. Get your **id** & **secret** from [GitHub (direct link)](https://github.com/settings/developers).
|
|
9
|
-
* 2. In GitHub, set your callback url to
|
|
10
|
-
* - [ ] dev: `http://_YOUR_LOCAL_URL:PORT_/api/auth_callback`
|
|
11
|
-
* - [ ] prod: `https://MY_SUPER_SITE/api/auth_callback`
|
|
12
|
-
* 3. In your project add a `.env` file with the following:
|
|
13
|
-
* ```bash
|
|
14
|
-
* GITHUB_CLIENT_ID = 'your-client-id'
|
|
15
|
-
* GITHUB_CLIENT_SECRET = 'your-client-secret'
|
|
16
|
-
* # GITHUB_REDIRECT_URI = '' # optional, will default to "${origin}/api/auth_callback"
|
|
17
|
-
* ```
|
|
18
|
-
* 4. In your frontend, under a button click call something like:
|
|
19
|
-
* ```ts
|
|
20
|
-
* async function oauth() {
|
|
21
|
-
* window.location.href = await Auth.signInOAuthGetUrl({ provider: 'github', redirect: window.location.pathname })
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
* 5. Enjoy 🥳
|
|
25
|
-
*/
|
|
26
|
-
export declare function github(options?: {
|
|
27
|
-
GITHUB_CLIENT_ID?: string;
|
|
28
|
-
GITHUB_CLIENT_SECRET?: string;
|
|
29
|
-
GITHUB_REDIRECT_URI?: string;
|
|
30
|
-
authorizationURLOptions?: ProviderAuthorizationURLOptions;
|
|
31
|
-
getUserInfo?: (tokens: OAuth2Tokens) => Promise<OAuth2UserInfo>;
|
|
32
|
-
log?: boolean;
|
|
33
|
-
}): FFOAuth2Provider<GitHub, 'github'>;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { GitHub } from 'arctic';
|
|
2
|
-
import { remult } from 'remult';
|
|
3
|
-
import { env } from '$env/dynamic/private';
|
|
4
|
-
import { authModuleRaw } from '../module';
|
|
5
|
-
import { checkOAuthConfig } from './helperProvider';
|
|
6
|
-
//------------------------------
|
|
7
|
-
// For developers (future me ?), To do another OAuth2 provider:
|
|
8
|
-
// Replace GITHUB / Github / github
|
|
9
|
-
// update "https://github.com/settings/developers" to the correct URL (2 places)
|
|
10
|
-
// update "https://api.github.com/user" the fetch user info
|
|
11
|
-
//------------------------------
|
|
12
|
-
/**
|
|
13
|
-
* ## GitHub OAuth2 provider
|
|
14
|
-
*
|
|
15
|
-
* 1. Get your **id** & **secret** from [GitHub (direct link)](https://github.com/settings/developers).
|
|
16
|
-
* 2. In GitHub, set your callback url to
|
|
17
|
-
* - [ ] dev: `http://_YOUR_LOCAL_URL:PORT_/api/auth_callback`
|
|
18
|
-
* - [ ] prod: `https://MY_SUPER_SITE/api/auth_callback`
|
|
19
|
-
* 3. In your project add a `.env` file with the following:
|
|
20
|
-
* ```bash
|
|
21
|
-
* GITHUB_CLIENT_ID = 'your-client-id'
|
|
22
|
-
* GITHUB_CLIENT_SECRET = 'your-client-secret'
|
|
23
|
-
* # GITHUB_REDIRECT_URI = '' # optional, will default to "${origin}/api/auth_callback"
|
|
24
|
-
* ```
|
|
25
|
-
* 4. In your frontend, under a button click call something like:
|
|
26
|
-
* ```ts
|
|
27
|
-
* async function oauth() {
|
|
28
|
-
* window.location.href = await Auth.signInOAuthGetUrl({ provider: 'github', redirect: window.location.pathname })
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
* 5. Enjoy 🥳
|
|
32
|
-
*/
|
|
33
|
-
export function github(options) {
|
|
34
|
-
const name = 'github';
|
|
35
|
-
const clientID = options?.GITHUB_CLIENT_ID ?? env.GITHUB_CLIENT_ID ?? '';
|
|
36
|
-
const secret = options?.GITHUB_CLIENT_SECRET ?? env.GITHUB_CLIENT_SECRET ?? '';
|
|
37
|
-
const urlForKeys = 'https://github.com/settings/developers';
|
|
38
|
-
checkOAuthConfig(name, clientID, secret, urlForKeys, false);
|
|
39
|
-
return {
|
|
40
|
-
name,
|
|
41
|
-
caption: 'GitHub',
|
|
42
|
-
getArcticProvider: () => {
|
|
43
|
-
const redirectURI = options?.GITHUB_REDIRECT_URI ??
|
|
44
|
-
env.GITHUB_REDIRECT_URI ??
|
|
45
|
-
`${remult.context.request.url.origin}/api/auth_callback`;
|
|
46
|
-
checkOAuthConfig(name, clientID, secret, urlForKeys, true);
|
|
47
|
-
const o = new GitHub(clientID, secret, redirectURI);
|
|
48
|
-
return o;
|
|
49
|
-
},
|
|
50
|
-
authorizationURLOptions: () => {
|
|
51
|
-
return options?.authorizationURLOptions ?? [];
|
|
52
|
-
},
|
|
53
|
-
getUserInfo: options?.getUserInfo
|
|
54
|
-
? options.getUserInfo
|
|
55
|
-
: async (tokens) => {
|
|
56
|
-
const res = await fetch('https://api.github.com/user', {
|
|
57
|
-
headers: {
|
|
58
|
-
Authorization: `Bearer ${tokens.accessToken()}`,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
const user = await res.json();
|
|
62
|
-
const nameOptions = [user.login];
|
|
63
|
-
const emailOptions = [];
|
|
64
|
-
if ((options?.authorizationURLOptions ?? ['user:email']).includes('user:email')) {
|
|
65
|
-
const res = await fetch('https://api.github.com/user/emails', {
|
|
66
|
-
headers: {
|
|
67
|
-
Authorization: `Bearer ${tokens.accessToken()}`,
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
user.emails = await res.json();
|
|
71
|
-
if (Array.isArray(user.emails)) {
|
|
72
|
-
const primaryEmails = user.emails.filter((email) => email.primary === true);
|
|
73
|
-
primaryEmails.forEach((email) => {
|
|
74
|
-
if (email.email) {
|
|
75
|
-
nameOptions.unshift(email.email);
|
|
76
|
-
emailOptions.unshift(email.email);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (options?.log) {
|
|
82
|
-
authModuleRaw.log.info(`user`, user);
|
|
83
|
-
}
|
|
84
|
-
return { raw: user, providerUserId: String(user.id), nameOptions, emailOptions };
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const checkOAuthConfig: (name: string, clientId: string, secret: string, urlForKeys: string, withThrow: boolean) => void;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { EntityError } from 'remult';
|
|
2
|
-
import { cyan, gray, green, italic, yellow } from '@kitql/helpers';
|
|
3
|
-
import { mask } from '../../../formats/strings';
|
|
4
|
-
import { authModuleRaw } from '../module';
|
|
5
|
-
export const checkOAuthConfig = (name, clientId, secret, urlForKeys, withThrow) => {
|
|
6
|
-
if (!clientId || !secret) {
|
|
7
|
-
const msg = `Wrong configuration for ${green(name)} provider.
|
|
8
|
-
${italic(`Config used ${gray(`(${'.env'} & ${'inferred'}):`)}`)}
|
|
9
|
-
${yellow('--------------- .env ---------------')}
|
|
10
|
-
${name.toUpperCase()}_CLIENT_ID = '${mask(clientId)}'
|
|
11
|
-
${name.toUpperCase()}_CLIENT_SECRET = '${mask(secret)}'
|
|
12
|
-
${yellow('------------------------------------')}
|
|
13
|
-
Update your configuration to fix this error.
|
|
14
|
-
${gray(`By default, we check ${name.toUpperCase()}_CLIENT_ID and ${name.toUpperCase()}_CLIENT_SECRET.
|
|
15
|
-
But you can also pass your keys as parameters.`)}
|
|
16
|
-
Check ${cyan(urlForKeys)} to generate your keys.
|
|
17
|
-
`;
|
|
18
|
-
if (withThrow) {
|
|
19
|
-
throw new EntityError({ message: msg });
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
authModuleRaw.log.error(msg);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.oauth-container.svelte-1dwkktf{display:flex;flex-direction:column;gap:.5rem}.oauth-button-icon.svelte-1dwkktf{width:1.25rem;height:1.25rem}.oauth-button.svelte-1dwkktf{display:flex;align-items:center;justify-content:center;gap:.5rem;padding:.5rem 1rem;font-size:.875rem;font-weight:500}form.svelte-skcj83{display:flex;flex-direction:column}h1.svelte-1jjivcr{text-align:center;margin-bottom:2rem}.wrapper.svelte-1jjivcr{min-height:100vh;display:flex;justify-content:center;align-items:center;margin:0 auto}.centered-layout.svelte-1jjivcr{display:flex;justify-content:center;align-items:center;width:100%}.split-layout.svelte-1jjivcr{display:flex;width:100%;min-height:100vh}.form-side.svelte-1jjivcr{width:50%;display:flex;justify-content:center;align-items:center}.image-side.svelte-1jjivcr{width:50%;height:100vh;overflow:hidden}.image-side.svelte-1jjivcr img:where(.svelte-1jjivcr){width:100%;height:100%;object-fit:cover}.form.svelte-1jjivcr{max-width:360px;width:100%;padding:1rem;display:flex;flex-direction:column}.form-footer.svelte-1jjivcr{margin-top:1rem;display:flex;flex-direction:column;justify-content:center;align-items:center}.fallback.svelte-1jjivcr{display:flex;justify-content:center;align-items:center}@media (max-width: 768px){.split-layout.svelte-1jjivcr{flex-direction:column}.form-side.svelte-1jjivcr{width:100%;order:2}.image-side.svelte-1jjivcr{width:100%;height:50vh;order:1}.form.svelte-1jjivcr{max-width:100%}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a9 as t,T as o}from"./index-D38rqu4x.js";function r(a){var e=t("Hello from files");o(a,e)}export{r as default};
|