nitro-web 0.0.168 → 0.0.169
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/client/app.tsx +12 -15
- package/client/index.ts +1 -1
- package/components/auth/auth.api.js +5 -1
- package/package.json +1 -1
- package/server/models/user.js +7 -4
- package/server/router.js +1 -0
- package/types/components/auth/auth.api.d.ts.map +1 -1
- package/types/server/models/user.d.ts +32 -24
- package/types/server/models/user.d.ts.map +1 -1
- package/types/server/router.d.ts.map +1 -1
- package/types.ts +1 -0
package/client/app.tsx
CHANGED
|
@@ -19,7 +19,7 @@ type Settings = {
|
|
|
19
19
|
// beforeStoreUpdate: (prevStore: Store | null, newData: Store) => Store
|
|
20
20
|
isStatic?: boolean
|
|
21
21
|
layouts: React.FC<LayoutProps>[]
|
|
22
|
-
|
|
22
|
+
allMiddleware: Record<string, (route: unknown, store: Store) => undefined | { redirect: string }>
|
|
23
23
|
name: string
|
|
24
24
|
titleSeparator?: string
|
|
25
25
|
}
|
|
@@ -52,7 +52,7 @@ export async function setupApp(config: Config, storeContainer: StoreContainer, l
|
|
|
52
52
|
beforeApp: config.beforeApp || beforeApp,
|
|
53
53
|
isStatic: config.isStatic,
|
|
54
54
|
layouts: layouts,
|
|
55
|
-
|
|
55
|
+
allMiddleware: Object.assign(middleware, config.middleware || {}),
|
|
56
56
|
name: config.name,
|
|
57
57
|
titleSeparator: config.titleSeparator,
|
|
58
58
|
}
|
|
@@ -165,9 +165,9 @@ function getRouter({ settings, config }: { settings: Settings, config: Config })
|
|
|
165
165
|
const layoutNum = (parseInt(String(route.meta?.layout || '1')) || 1) - 1
|
|
166
166
|
|
|
167
167
|
// get the routes middleware
|
|
168
|
-
const
|
|
168
|
+
const routeMiddleware = toArray(route[routePath]).filter((policyNameOrTrue) => {
|
|
169
169
|
if (policyNameOrTrue === true) return // ignore true
|
|
170
|
-
else if (policyNameOrTrue in settings.
|
|
170
|
+
else if (policyNameOrTrue in settings.allMiddleware) return true
|
|
171
171
|
else console.error(`No middleware named '${policyNameOrTrue}' defined under config.middleware, skipping..`)
|
|
172
172
|
})
|
|
173
173
|
|
|
@@ -180,7 +180,7 @@ function getRouter({ settings, config }: { settings: Settings, config: Config })
|
|
|
180
180
|
layout: layoutNum,
|
|
181
181
|
title: `${route.meta?.title ? `${route.meta.title}${settings.titleSeparator || ' - '}` : ''}${settings.name}`,
|
|
182
182
|
},
|
|
183
|
-
middleware:
|
|
183
|
+
middleware: routeMiddleware as string[],
|
|
184
184
|
name: componentName,
|
|
185
185
|
path: routePath,
|
|
186
186
|
redirect: route.redirect,
|
|
@@ -218,7 +218,7 @@ function getRouter({ settings, config }: { settings: Settings, config: Config })
|
|
|
218
218
|
await setTimeoutPromise(() => {}, 0)
|
|
219
219
|
}
|
|
220
220
|
for (const key of route.middleware) {
|
|
221
|
-
const error = settings.
|
|
221
|
+
const error = settings.allMiddleware[key](route, exposedStoreData || {})
|
|
222
222
|
// Note: the redirect uses the new pathname for query string values, e.g. '?example=value'. We also can't use the
|
|
223
223
|
// current pathname, as this doesn't exist on page refresh.
|
|
224
224
|
if (error && error.redirect) {
|
|
@@ -317,22 +317,19 @@ async function beforeApp(config: Config) {
|
|
|
317
317
|
return { ...storeData, apiAvailable }
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
-
const
|
|
321
|
-
//
|
|
320
|
+
export const middleware = {
|
|
321
|
+
// Default middleware that can referenced from component routes
|
|
322
322
|
isAdmin: (route: unknown, store: { user?: { type?: string, isAdmin?: boolean } }) => {
|
|
323
|
-
|
|
324
|
-
if (user
|
|
325
|
-
else if (user?.type && user?.type !== 'visitor') return { redirect: '/signin?unauth' }
|
|
323
|
+
if (store.user?.type?.match(/admin/) || store.user?.isAdmin) return
|
|
324
|
+
else if (store.user) return { redirect: '/signin?unauth' }
|
|
326
325
|
else return { redirect: '/signin?signin' }
|
|
327
326
|
},
|
|
328
327
|
isSubscribed: (route: unknown, store: { user?: { company?: { currentSubscription?: string } } }) => {
|
|
329
|
-
|
|
330
|
-
if (!user?.company?.currentSubscription) return
|
|
328
|
+
if (store.user?.company?.currentSubscription) return
|
|
331
329
|
else return { redirect: '/plans/subscribe' }
|
|
332
330
|
},
|
|
333
331
|
isUser: (route: unknown, store: { user?: { type?: string } }) => {
|
|
334
|
-
|
|
335
|
-
if (user?.type !== 'visitor') return
|
|
332
|
+
if (store.user) return
|
|
336
333
|
else return { redirect: '/signin?signin' }
|
|
337
334
|
},
|
|
338
335
|
}
|
package/client/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ export * as util from 'nitro-web/util'
|
|
|
9
9
|
export * from '../types'
|
|
10
10
|
|
|
11
11
|
// Main app functions
|
|
12
|
-
export { setupApp, updateJwt } from './app'
|
|
12
|
+
export { setupApp, updateJwt, middleware } from './app'
|
|
13
13
|
export { createStore, exposedStoreData, preloadedStoreData, setStoreWrapper } from './store'
|
|
14
14
|
|
|
15
15
|
// Component Pages
|
|
@@ -420,10 +420,14 @@ export async function sendToken({ type = 'reset', user, beforeUpdate, beforeSend
|
|
|
420
420
|
if (!user?.firstName) throw new Error('user.firstName is required')
|
|
421
421
|
const token = await tokenCreate(user._id)
|
|
422
422
|
|
|
423
|
+
// get the data
|
|
424
|
+
const data = beforeUpdate ? beforeUpdate({ [type + 'Token']: token }) : { [type + 'Token']: token }
|
|
425
|
+
if (type === 'invite') data.isInvited = true
|
|
426
|
+
|
|
423
427
|
// Update the user with the token
|
|
424
428
|
const result = await db.user.update({
|
|
425
429
|
query: { _id: user._id },
|
|
426
|
-
data:
|
|
430
|
+
data: data,
|
|
427
431
|
blacklist: ['-' + type + 'Token'],
|
|
428
432
|
})
|
|
429
433
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-web",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.169",
|
|
4
4
|
"repository": "github:boycce/nitro-web",
|
|
5
5
|
"homepage": "https://boycce.github.io/nitro-web/",
|
|
6
6
|
"description": "Nitro is a battle-tested, modular base project to turbocharge your projects, styled using Tailwind 🚀",
|
package/server/models/user.js
CHANGED
|
@@ -7,20 +7,23 @@ export default {
|
|
|
7
7
|
avatar: { type: 'image' },
|
|
8
8
|
company: { model: 'company', required: true },
|
|
9
9
|
email: { type: 'email', required: true, index: 'unique' },
|
|
10
|
+
isInvited: { type: 'boolean' },
|
|
10
11
|
firstName: { type: 'string', required: true },
|
|
11
12
|
lastName: { type: 'string', required: true },
|
|
12
|
-
password: { type: 'string', minLength: 6 },
|
|
13
|
-
resetToken: { type: 'string' },
|
|
14
13
|
status: { type: 'string', default: 'active', enum: ['active', 'deleted', 'inactive'] },
|
|
15
14
|
stripeCustomer: { type: 'any' },
|
|
16
15
|
stripeSubscription: { type: 'any' },
|
|
17
16
|
stripeIntents: { type: 'any' },
|
|
18
17
|
type: { type: 'string', default: 'user', enum: ['user', 'admin'] },
|
|
19
18
|
usedFreeTrial: { type: 'boolean', default: false },
|
|
19
|
+
// hidden fields
|
|
20
|
+
password: { type: 'string', minLength: 6 },
|
|
21
|
+
inviteToken: { type: 'string' },
|
|
22
|
+
resetToken: { type: 'string' },
|
|
20
23
|
},
|
|
21
24
|
|
|
22
|
-
findBL: ['password', 'resetToken'],
|
|
23
|
-
updateBL: ['
|
|
25
|
+
findBL: ['password', 'inviteToken', 'resetToken'],
|
|
26
|
+
updateBL: ['password', 'inviteToken', 'resetToken', 'company', 'status', 'stripeSubscription', 'type', 'usedFreeTrial'],
|
|
24
27
|
|
|
25
28
|
messages: {
|
|
26
29
|
lastName: {
|
package/server/router.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.api.d.ts","sourceRoot":"","sources":["../../../components/auth/auth.api.js"],"names":[],"mappings":"AAkLA,qGAyCC;AAED;;GAKC;AAED,0FAQC;AAED;;;;iBAkDC;AAED,mDAOC;AAED,4CAYC;AAED,kFAiBC;AAOD,qEAeC;AAED,sEAWC;AAED,iEAMC;AAED,gEAMC;AAID,wEAoBC;AAED;;;;;;;;GAQG;AACH,yEANG;IAAoC,IAAI,EAAhC,OAAO,GAAG,QAAQ;IACuC,IAAI,EAA7D;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC;IAC5B,YAAY;IACZ,eAAe;CAC1C,GAAU,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"auth.api.d.ts","sourceRoot":"","sources":["../../../components/auth/auth.api.js"],"names":[],"mappings":"AAkLA,qGAyCC;AAED;;GAKC;AAED,0FAQC;AAED;;;;iBAkDC;AAED,mDAOC;AAED,4CAYC;AAED,kFAiBC;AAOD,qEAeC;AAED,sEAWC;AAED,iEAMC;AAED,gEAMC;AAID,wEAoBC;AAED;;;;;;;;GAQG;AACH,yEANG;IAAoC,IAAI,EAAhC,OAAO,GAAG,QAAQ;IACuC,IAAI,EAA7D;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC;IAC5B,YAAY;IACZ,eAAe;CAC1C,GAAU,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;CAAC,CAAC,CAoCtE;AApbD;;;;;;;;;;;;;;;;;;;;EA6BC;AAmED,0DAEC;AAkCD,mDAEC;AAnBD,iDAeC;AA9BD,2DAaC;AAuBD,2DAwBC;AAjID,4DA+DC"}
|
|
@@ -14,62 +14,70 @@ declare namespace _default {
|
|
|
14
14
|
export { required_1 as required };
|
|
15
15
|
export let index: string;
|
|
16
16
|
}
|
|
17
|
-
export namespace
|
|
17
|
+
export namespace isInvited {
|
|
18
18
|
let type_2: string;
|
|
19
19
|
export { type_2 as type };
|
|
20
|
-
let required_2: boolean;
|
|
21
|
-
export { required_2 as required };
|
|
22
20
|
}
|
|
23
|
-
export namespace
|
|
21
|
+
export namespace firstName {
|
|
24
22
|
let type_3: string;
|
|
25
23
|
export { type_3 as type };
|
|
26
|
-
let
|
|
27
|
-
export {
|
|
24
|
+
let required_2: boolean;
|
|
25
|
+
export { required_2 as required };
|
|
28
26
|
}
|
|
29
|
-
export namespace
|
|
27
|
+
export namespace lastName {
|
|
30
28
|
let type_4: string;
|
|
31
29
|
export { type_4 as type };
|
|
32
|
-
|
|
30
|
+
let required_3: boolean;
|
|
31
|
+
export { required_3 as required };
|
|
33
32
|
}
|
|
34
|
-
export namespace
|
|
33
|
+
export namespace status {
|
|
35
34
|
let type_5: string;
|
|
36
35
|
export { type_5 as type };
|
|
37
|
-
}
|
|
38
|
-
export namespace status {
|
|
39
|
-
let type_6: string;
|
|
40
|
-
export { type_6 as type };
|
|
41
36
|
let _default: string;
|
|
42
37
|
export { _default as default };
|
|
43
38
|
let _enum: string[];
|
|
44
39
|
export { _enum as enum };
|
|
45
40
|
}
|
|
46
41
|
export namespace stripeCustomer {
|
|
42
|
+
let type_6: string;
|
|
43
|
+
export { type_6 as type };
|
|
44
|
+
}
|
|
45
|
+
export namespace stripeSubscription {
|
|
47
46
|
let type_7: string;
|
|
48
47
|
export { type_7 as type };
|
|
49
48
|
}
|
|
50
|
-
export namespace
|
|
49
|
+
export namespace stripeIntents {
|
|
51
50
|
let type_8: string;
|
|
52
51
|
export { type_8 as type };
|
|
53
52
|
}
|
|
54
|
-
export namespace
|
|
55
|
-
let
|
|
56
|
-
export {
|
|
57
|
-
}
|
|
58
|
-
export namespace type_10 {
|
|
59
|
-
let type_11: string;
|
|
60
|
-
export { type_11 as type };
|
|
53
|
+
export namespace type_9 {
|
|
54
|
+
let type_10: string;
|
|
55
|
+
export { type_10 as type };
|
|
61
56
|
let _default_1: string;
|
|
62
57
|
export { _default_1 as default };
|
|
63
58
|
let _enum_1: string[];
|
|
64
59
|
export { _enum_1 as enum };
|
|
65
60
|
}
|
|
66
|
-
export {
|
|
61
|
+
export { type_9 as type };
|
|
67
62
|
export namespace usedFreeTrial {
|
|
68
|
-
let
|
|
69
|
-
export {
|
|
63
|
+
let type_11: string;
|
|
64
|
+
export { type_11 as type };
|
|
70
65
|
let _default_2: boolean;
|
|
71
66
|
export { _default_2 as default };
|
|
72
67
|
}
|
|
68
|
+
export namespace password {
|
|
69
|
+
let type_12: string;
|
|
70
|
+
export { type_12 as type };
|
|
71
|
+
export let minLength: number;
|
|
72
|
+
}
|
|
73
|
+
export namespace inviteToken {
|
|
74
|
+
let type_13: string;
|
|
75
|
+
export { type_13 as type };
|
|
76
|
+
}
|
|
77
|
+
export namespace resetToken {
|
|
78
|
+
let type_14: string;
|
|
79
|
+
export { type_14 as type };
|
|
80
|
+
}
|
|
73
81
|
}
|
|
74
82
|
let findBL: string[];
|
|
75
83
|
let updateBL: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../server/models/user.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../server/models/user.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAiDmB,gCAEd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../server/router.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../server/router.js"],"names":[],"mappings":"AAoCA,wHA6HC;AAoPD,+CAEC;AAED,kEAYC;AApGD,+BAA+B;AAC/B,yBADW,gBAAgB,CAkF1B;sBAnYY,OAAO,CAAC,OAAO,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAoB,CAAC;CAC7B;uBACS,OAAO,CAAC,QAAQ,GAAG;IAC3B,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACjE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC;IACvD,SAAS,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC;IACpD,QAAQ,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC;IACnD,WAAW,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC;CACvD;+BACS;IACR,KAAK,EAAE,MAAM,EAAE,CAAC;IACpB,CAAK,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,UAAU,KAAK,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC;CACnF;iBA1Ba,MAAM;oBAIH,SAAS"}
|