nitro-web 0.0.74 → 0.0.76

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.
@@ -6,7 +6,7 @@ import { Strategy as JwtStrategy, ExtractJwt } from 'passport-jwt'
6
6
  import db from 'monastery'
7
7
  import jsonwebtoken from 'jsonwebtoken'
8
8
  import { sendEmail } from 'nitro-web/server'
9
- import { isArray, pick, isString, ucFirst, fullNameSplit } from 'nitro-web/util'
9
+ import { isArray, pick, ucFirst, fullNameSplit } from 'nitro-web/util'
10
10
 
11
11
  let authConfig = null
12
12
  const JWT_SECRET = process.env.JWT_SECRET || 'replace_this_with_secure_env_secret'
@@ -106,7 +106,7 @@ async function store(req, res) {
106
106
  async function signup(req, res) {
107
107
  try {
108
108
  const desktop = req.query.desktop
109
- let user = await this.userCreate(req.body, this.findUserFromProvider)
109
+ let user = await this.userCreate(req.body)
110
110
  sendEmail({
111
111
  config: authConfig,
112
112
  template: 'welcome',
@@ -315,8 +315,12 @@ export async function signinAndGetStore(user, isDesktop, getStore) {
315
315
  return { ...store, jwt }
316
316
  }
317
317
 
318
- export async function userCreate({ name, business, email, password, findUserFromProvider }) {
318
+ export async function userCreate({ name, business, email, password }) {
319
319
  try {
320
+ if (!this.findUserFromProvider) {
321
+ throw new Error('this.findUserFromProvider doesn\'t exist, make sure the context is available when calling this function')
322
+ }
323
+
320
324
  const options = { blacklist: ['-_id'] }
321
325
  const isMultiTenant = !authConfig.isNotMultiTenant
322
326
  const userId = db.id()
@@ -22,7 +22,7 @@ type FieldExtraProps = {
22
22
  /** icon to show in the input */
23
23
  icon?: React.ReactNode
24
24
  iconPos?: 'left' | 'right'
25
- /** Pass dependencies to break memoization, handy for onChange/onInputChange */
25
+ /** Dependencies to break the implicit memoization of onChange/onInputChange */
26
26
  deps?: unknown[]
27
27
  placeholder?: string
28
28
  }
@@ -181,25 +181,19 @@ function ColorSvg({ hex }: { hex?: string }) {
181
181
  }
182
182
 
183
183
  export function isFieldCached(prev: IsFieldCachedProps, next: IsFieldCachedProps) {
184
+ // Check if the field is cached, onChange/onInputChange doesn't affect the cache
184
185
  const path = prev.name
185
186
  const state = prev.state || {}
186
- // If state/satte-error values have changed, re-render!
187
- if (deepFind(state, path) !== deepFind(next.state || {}, path)) {
188
- // console.log(1, 'state changed', path)
189
- return false
190
- }
191
- if (getErrorFromState(state, path) !== getErrorFromState(next.state || {}, path)) {
192
- // console.log(2, 'error changed', path)
193
- return false
194
- }
195
- // If deps have changed, re-render!
196
- if ((next.deps?.length !== prev.deps?.length) || next.deps?.some((v, i) => v !== prev.deps?.[i])) {
197
- // console.log(3, 'deps changed', path)
198
- return false
199
- }
200
- // If any other props have changed, except onChange/onInputChange, re-render!
201
- // In most cases, onChange/onInputChange remain the same and reference the same function...
202
- for (const k in prev) {
187
+ // If the state value has changed, re-render!
188
+ if (deepFind(state, path) !== deepFind(next.state || {}, path)) return false
189
+ // If the state error has changed, re-render!
190
+ if (getErrorFromState(state, path) !== getErrorFromState(next.state || {}, path)) return false
191
+ // If `deps` have changed, handy for onChange/onInputChange, re-render!
192
+ if ((next.deps?.length !== prev.deps?.length) || next.deps?.some((v, i) => v !== prev.deps?.[i])) return false
193
+
194
+ // Check if any prop has changed, except `onChange`/`onInputChange`
195
+ const allKeys = new Set([...Object.keys(prev), ...Object.keys(next)])
196
+ for (const k of allKeys) {
203
197
  if (k === 'state' || k === 'onChange' || k === 'onInputChange') continue
204
198
  if (prev[k as keyof typeof prev] !== next[k as keyof typeof next]) {
205
199
  // console.log(4, 'changed', path, k)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitro-web",
3
- "version": "0.0.74",
3
+ "version": "0.0.76",
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 🚀",
@@ -1,6 +1,6 @@
1
1
  <!--
2
- - You can view templates at http://localhost:3001/email/reset-password
3
- - To modify the css, add your own /server/email/partials/email.css file
2
+ - You can view templates at http://localhost:3000/email/reset-password
3
+ - To modify the css, add your own ./server/email/partials/email.css file
4
4
  - You can copy any nitro email .swig/html template to your project, and modify it
5
5
  -->
6
6
 
@@ -1,6 +1,6 @@
1
1
  <!--
2
- - You can view templates at http://localhost:3001/email/welcome
3
- - To modify the css, add your own /server/email/partials/email.css file
2
+ - You can view templates at http://localhost:3000/email/welcome
3
+ - To modify the css, add your own ./server/email/partials/email.css file
4
4
  - You can copy any nitro email .swig/html template to your project, and modify it
5
5
  -->
6
6
 
package/server/router.js CHANGED
@@ -98,7 +98,8 @@ export async function setupRouter (config) {
98
98
  let indexExists = !!fs.existsSync(distDir + 'index.html')
99
99
 
100
100
  // Register email routes for development
101
- // E.g. http://localhost:3001/email/welcome
101
+ // E.g. http://localhost:3001/email/welcome Or
102
+ // E.g. http://localhost:3000/email/welcome (with webpack-dev-server proxy)
102
103
  if (env == 'development') {
103
104
  expressApp.get('/email/partials/email.css', (req, res) => {
104
105
  // first check if there is a custom email.css in the emailTemplateDir