rlz-engine 1.0.19 → 1.0.20
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { JSX } from 'react';
|
|
2
2
|
interface SignupSigninScreenProps {
|
|
3
3
|
appName: string;
|
|
4
4
|
}
|
|
5
|
-
export declare
|
|
5
|
+
export declare function SignupSigninScreen({ appName }: SignupSigninScreenProps): JSX.Element;
|
|
6
6
|
export {};
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { Box, Button, CircularProgress, Stack, Tab, Tabs, TextField, Typography } from '@mui/material';
|
|
2
|
-
import { observer } from 'mobx-react-lite';
|
|
3
2
|
import React from 'react';
|
|
4
3
|
import { useCallback, useState } from 'react';
|
|
5
4
|
import { useLocation, useNavigate } from 'react-router-dom';
|
|
6
5
|
import { z } from 'zod';
|
|
7
6
|
import { apiSignin, apiSignup } from '../api/auth';
|
|
8
7
|
import { useAuthState } from '../state/auth';
|
|
9
|
-
|
|
10
|
-
export const SignupSigninScreen = observer(function SignupSigninScreen({ appName }) {
|
|
8
|
+
export function SignupSigninScreen({ appName }) {
|
|
11
9
|
const location = useLocation();
|
|
12
10
|
const navigate = useNavigate();
|
|
13
11
|
const tab = location.pathname.substring(1);
|
|
@@ -22,9 +20,8 @@ export const SignupSigninScreen = observer(function SignupSigninScreen({ appName
|
|
|
22
20
|
&& React.createElement(SignupForm, null),
|
|
23
21
|
tab === 'signin'
|
|
24
22
|
&& React.createElement(SigninForm, null)));
|
|
25
|
-
}
|
|
23
|
+
}
|
|
26
24
|
function SignupForm() {
|
|
27
|
-
const authState = useAuthState();
|
|
28
25
|
const navigate = useNavigate();
|
|
29
26
|
const [syncInProgress, setSyncInProgress] = useState(false);
|
|
30
27
|
const [name, setName] = useState('');
|
|
@@ -39,7 +36,7 @@ function SignupForm() {
|
|
|
39
36
|
setSyncInProgress(true);
|
|
40
37
|
setTimeout(async () => {
|
|
41
38
|
try {
|
|
42
|
-
await signup(name, email, password, password2
|
|
39
|
+
await signup(name, email, password, password2);
|
|
43
40
|
void navigate('/');
|
|
44
41
|
}
|
|
45
42
|
finally {
|
|
@@ -73,7 +70,8 @@ function SignupForm() {
|
|
|
73
70
|
marginLeft: '-12px'
|
|
74
71
|
} })))));
|
|
75
72
|
}
|
|
76
|
-
async function signup(name, email, password, password2
|
|
73
|
+
async function signup(name, email, password, password2) {
|
|
74
|
+
const login = useAuthState(i => i.login);
|
|
77
75
|
if (name === ''
|
|
78
76
|
|| !isValidEmail(email)
|
|
79
77
|
|| password === ''
|
|
@@ -81,10 +79,9 @@ async function signup(name, email, password, password2, authState) {
|
|
|
81
79
|
return;
|
|
82
80
|
}
|
|
83
81
|
const resp = await apiSignup(name, email, password);
|
|
84
|
-
|
|
82
|
+
login(resp.id, resp.name, resp.email, resp.tempPassword);
|
|
85
83
|
}
|
|
86
84
|
function SigninForm() {
|
|
87
|
-
const authState = useAuthState();
|
|
88
85
|
const [syncInProgress, setSyncInProgress] = useState(false);
|
|
89
86
|
const navigate = useNavigate();
|
|
90
87
|
const [name, setName] = useState('');
|
|
@@ -93,7 +90,7 @@ function SigninForm() {
|
|
|
93
90
|
setSyncInProgress(true);
|
|
94
91
|
setTimeout(async () => {
|
|
95
92
|
try {
|
|
96
|
-
await signin(name, password
|
|
93
|
+
await signin(name, password);
|
|
97
94
|
void navigate('/');
|
|
98
95
|
}
|
|
99
96
|
finally {
|
|
@@ -120,9 +117,10 @@ function SigninForm() {
|
|
|
120
117
|
marginLeft: '-12px'
|
|
121
118
|
} })))));
|
|
122
119
|
}
|
|
123
|
-
async function signin(name, password
|
|
120
|
+
async function signin(name, password) {
|
|
121
|
+
const login = useAuthState(i => i.login);
|
|
124
122
|
const resp = await apiSignin(name, password);
|
|
125
|
-
|
|
123
|
+
login(resp.id, resp.name, resp.email, resp.tempPassword);
|
|
126
124
|
}
|
|
127
125
|
function isValidEmail(s) {
|
|
128
126
|
return z.string().email().safeParse(s).success;
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import { AuthParam } from '../api/api';
|
|
2
|
-
|
|
2
|
+
interface AuthState {
|
|
3
3
|
id: string | null;
|
|
4
4
|
name: string | null;
|
|
5
5
|
email: string | null;
|
|
6
6
|
tempPassword: string | null;
|
|
7
|
-
|
|
8
|
-
logout()
|
|
9
|
-
login(id: string, name: string, email: string, tempPassword: string): void;
|
|
10
|
-
get authParam(): AuthParam | null;
|
|
7
|
+
login: (id: string, name: string, email: string, tempPassword: string) => void;
|
|
8
|
+
logout: () => void;
|
|
11
9
|
}
|
|
12
|
-
export declare const
|
|
13
|
-
|
|
10
|
+
export declare const useAuthState: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<AuthState>, "persist"> & {
|
|
11
|
+
persist: {
|
|
12
|
+
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<AuthState, AuthState>>) => void;
|
|
13
|
+
clearStorage: () => void;
|
|
14
|
+
rehydrate: () => Promise<void> | void;
|
|
15
|
+
hasHydrated: () => boolean;
|
|
16
|
+
onHydrate: (fn: (state: AuthState) => void) => () => void;
|
|
17
|
+
onFinishHydration: (fn: (state: AuthState) => void) => () => void;
|
|
18
|
+
getOptions: () => Partial<import("zustand/middleware").PersistOptions<AuthState, AuthState>>;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
export declare function useAuthParam(): AuthParam | null;
|
|
22
|
+
export {};
|
|
@@ -1,77 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
import { persist } from 'zustand/middleware';
|
|
3
3
|
const AUTH_ID_KEY = 'AUTH_ID';
|
|
4
4
|
const AUTH_NAME_KEY = 'AUTH_NAME';
|
|
5
5
|
const AUTH_EMAIL_KEY = 'AUTH_EMAIL';
|
|
6
6
|
const AUTH_TEMP_PASSWORD_KEY = 'AUTH_TEMP_PASSWORD';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
tempPassword = localStorage.getItem(AUTH_TEMP_PASSWORD_KEY);
|
|
12
|
-
constructor() {
|
|
13
|
-
makeAutoObservable(this);
|
|
14
|
-
autorun(() => {
|
|
15
|
-
if (this.id !== null) {
|
|
16
|
-
localStorage.setItem(AUTH_ID_KEY, this.id);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
localStorage.removeItem(AUTH_ID_KEY);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
autorun(() => {
|
|
23
|
-
if (this.name !== null) {
|
|
24
|
-
localStorage.setItem(AUTH_NAME_KEY, this.name);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
localStorage.removeItem(AUTH_NAME_KEY);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
autorun(() => {
|
|
31
|
-
if (this.email !== null) {
|
|
32
|
-
localStorage.setItem(AUTH_EMAIL_KEY, this.email);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
localStorage.removeItem(AUTH_EMAIL_KEY);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
autorun(() => {
|
|
39
|
-
if (this.tempPassword !== null) {
|
|
40
|
-
localStorage.setItem(AUTH_TEMP_PASSWORD_KEY, this.tempPassword);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
localStorage.removeItem(AUTH_TEMP_PASSWORD_KEY);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
logout() {
|
|
48
|
-
this.id = null;
|
|
49
|
-
this.name = null;
|
|
50
|
-
this.email = null;
|
|
51
|
-
this.tempPassword = null;
|
|
52
|
-
}
|
|
53
|
-
login(id, name, email, tempPassword) {
|
|
54
|
-
this.id = id;
|
|
55
|
-
this.name = name;
|
|
56
|
-
this.email = email;
|
|
57
|
-
this.tempPassword = tempPassword;
|
|
58
|
-
}
|
|
59
|
-
get authParam() {
|
|
60
|
-
if (this.id === null || this.tempPassword === null) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
userId: this.id,
|
|
65
|
-
tempPassword: this.tempPassword
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
7
|
+
localStorage.removeItem(AUTH_ID_KEY);
|
|
8
|
+
localStorage.removeItem(AUTH_NAME_KEY);
|
|
9
|
+
localStorage.removeItem(AUTH_EMAIL_KEY);
|
|
10
|
+
localStorage.removeItem(AUTH_TEMP_PASSWORD_KEY);
|
|
69
11
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
70
|
-
export const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
12
|
+
export const useAuthState = create()(persist(set => ({
|
|
13
|
+
id: null,
|
|
14
|
+
name: null,
|
|
15
|
+
email: null,
|
|
16
|
+
tempPassword: null,
|
|
17
|
+
login: (id, name, email, tempPassword) => set({ id, name, email, tempPassword }),
|
|
18
|
+
logout: () => set({ id: null, name: null, email: null, tempPassword: null })
|
|
19
|
+
}), { name: 'AUTH' }));
|
|
20
|
+
export function useAuthParam() {
|
|
21
|
+
const id = useAuthState(i => i.id);
|
|
22
|
+
const tempPassword = useAuthState(i => i.tempPassword);
|
|
23
|
+
if (id === null || tempPassword === null) {
|
|
24
|
+
return null;
|
|
75
25
|
}
|
|
76
|
-
return
|
|
26
|
+
return {
|
|
27
|
+
userId: id,
|
|
28
|
+
tempPassword
|
|
29
|
+
};
|
|
77
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rlz-engine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "Deps and tools for my style of development",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc",
|
|
@@ -55,8 +55,6 @@
|
|
|
55
55
|
"fastify-plugin": "^5.0.1",
|
|
56
56
|
"iterator-helpers-polyfill": "^3.0.1",
|
|
57
57
|
"luxon": "^3.5.0",
|
|
58
|
-
"mobx": "^6.13.5",
|
|
59
|
-
"mobx-react-lite": "^4.1.0",
|
|
60
58
|
"mongodb": "^6.12.0",
|
|
61
59
|
"pino": "^9.5.0",
|
|
62
60
|
"pino-pretty": "^13.0.0",
|
|
@@ -66,6 +64,7 @@
|
|
|
66
64
|
"react-router-dom": "^7.1.1",
|
|
67
65
|
"uuidv7": "^1.0.2",
|
|
68
66
|
"zod": "^3.23.8",
|
|
69
|
-
"zod-to-json-schema": "^3.23.5"
|
|
67
|
+
"zod-to-json-schema": "^3.23.5",
|
|
68
|
+
"zustand": "^5.0.3"
|
|
70
69
|
}
|
|
71
70
|
}
|