Skip to content

Commit a0edfab

Browse files
BA-1430: dependencies update (#97)
1 parent b735020 commit a0edfab

File tree

117 files changed

+2608
-2596
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+2608
-2596
lines changed

apps/docs/pages/auth/index.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { axios, useLogin } from '@baseapp-frontend/core'
2-
import { ButtonWithLoading, PasswordField, TextField } from '@baseapp-frontend/design-system-mui'
2+
import { ButtonWithLoading } from '@baseapp-frontend/design-system-mui'
33

44
import { Divider, useTheme } from '@mui/material'
55
import MockAdapter from 'axios-mock-adapter'
@@ -43,8 +43,6 @@ export default function Auth() {
4343
onSubmit={mockForSuccessAndLogIn}
4444
style={{ display: 'flex', flexDirection: 'column', maxWidth: '300px' }}
4545
>
46-
<TextField name="email" label="Email" form={form} sx={{ marginBottom: '14px' }} />
47-
<PasswordField name="password" label="Password" form={form} sx={{ marginBottom: '14px' }} />
4846
<div style={{ display: 'flex' }}>
4947
<ButtonWithLoading
5048
variant="contained"

apps/docs/pages/components/index.tsx

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { useState } from 'react'
22

3-
import {
4-
ButtonWithLoading,
5-
CheckboxField,
6-
ImageUploader,
7-
PasswordField,
8-
} from '@baseapp-frontend/design-system-mui'
3+
import { ButtonWithLoading, ImageUploader } from '@baseapp-frontend/design-system-mui'
94

105
import { Divider, useTheme } from '@mui/material'
116

@@ -30,17 +25,6 @@ export default function Docs() {
3025

3126
<Divider style={{ margin: theme.spacing(2, 0) }} />
3227

33-
<div style={{ width: theme.spacing(48) }}>
34-
<h2>{`<PasswordField />`}</h2>
35-
<PasswordField name="password" />
36-
37-
<PasswordField name="password" helperText="Type your password." />
38-
39-
<PasswordField name="password" error helperText="Incorrect entry." />
40-
</div>
41-
42-
<Divider style={{ margin: theme.spacing(2, 0) }} />
43-
4428
<h2>{`<ImageUploader />`}</h2>
4529
<div style={{ width: theme.spacing(48) }}>
4630
<ImageUploader
@@ -52,10 +36,6 @@ export default function Docs() {
5236
buttonRemoveLabel="Remove"
5337
/>
5438
</div>
55-
56-
<Divider style={{ margin: theme.spacing(2, 0) }} />
57-
58-
<CheckboxField name="checkbox" label="Checkbox" />
5939
</div>
6040
)
6141
}

apps/storybook-app/components/Checkbox/index.tsx

-3
This file was deleted.

apps/storybook-app/components/Checkbox/stories.tsx

-17
This file was deleted.

apps/storybook-app/components/PasswordField/index.tsx

-3
This file was deleted.

apps/storybook-app/components/PasswordField/stories.tsx

-15
This file was deleted.

apps/storybook-app/components/TextField/index.tsx

-6
This file was deleted.

apps/storybook-app/components/TextField/stories.tsx

-13
This file was deleted.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"packages/*"
99
],
1010
"scripts": {
11-
"build": "turbo run build",
11+
"build": "turbo run build --filter=docs^...",
1212
"clean": "turbo run clean && rm -rf node_modules && rm -rf ./apps/*/node_modules && rm -rf ./packages/*/node_modules && rm -rf",
1313
"dev": "turbo run dev --parallel",
1414
"lint": "turbo run lint",
@@ -26,11 +26,11 @@
2626
"husky": "^8.0.0",
2727
"lint-staged": "^13.0.2",
2828
"prettier": "^2.8.8",
29-
"turbo": "latest"
29+
"turbo": "^2.0.3"
3030
},
3131
"engines": {
3232
"npm": ">=7.0.0",
33-
"node": ">=14.0.0"
33+
"node": ">=18.0.0"
3434
},
3535
"lint-staged": {
3636
"apps/**/*.{js,ts,jsx,tsx}": [

packages/authentication/CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# @baseapp-frontend/authentication
22

3+
## 3.0.0
4+
5+
### Major Changes
6+
7+
- Migrate to React Query v5. This includes adapting the code due to breaking changes of the library.
8+
- Update several dependencies.
9+
- Remove deprecated `usePreAuth` hook. We should now pre authenticate on the server side using the `preAuthenticate` function.
10+
- Renamed a couple of type interfaces, mainly removing the `I` prefix from it.
11+
- Move `react`, `@baseapp-frontend/provider` and `@baseapp-frontend/utils` to `peerDependencies` for better compatibility between the packages and the consumer app.
12+
13+
### Patch Changes
14+
15+
- Updated dependencies
16+
- @baseapp-frontend/provider@2.0.0
17+
- @baseapp-frontend/utils@2.4.0
18+
319
## 2.2.0
420

521
### Minor Changes

packages/authentication/modules/access/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,3 @@ export type * from './useResetPassword/types'
1515

1616
export { default as useSignUp } from './useSignUp'
1717
export type * from './useSignUp/types'
18-
19-
export { default as usePreAuth } from './usePreAuth'
20-
export type * from './usePreAuth/types'

packages/authentication/modules/access/preAuthenticateJWT/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { baseAppFetch } from '@baseapp-frontend/utils/functions/fetch/baseAppFetch'
2-
import type { IJWTResponse } from '@baseapp-frontend/utils/types/jwt'
2+
import type { JWTResponse } from '@baseapp-frontend/utils/types/jwt'
33

44
const preAuthenticateJWT = async (token?: string) => {
55
try {
66
if (!token) {
77
throw new Error('No token provided.')
88
}
99

10-
const response = await baseAppFetch<IJWTResponse>('/auth/pre-auth/jwt', {
10+
const response = await baseAppFetch<JWTResponse>('/auth/pre-auth/jwt', {
1111
method: 'POST',
1212
body: { token },
1313
})

packages/authentication/modules/access/useLogin/constants.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { ZOD_MESSAGE } from '@baseapp-frontend/utils'
22

33
import { z } from 'zod'
44

5-
import { ILoginRequest } from '../../../types/auth'
5+
import { LoginRequest } from '../../../types/auth'
66

77
export const DEFAULT_VALIDATION_SCHEMA = z.object({
8-
email: z.string().nonempty(ZOD_MESSAGE.required).email(ZOD_MESSAGE.email),
9-
password: z.string().nonempty(ZOD_MESSAGE.required),
8+
email: z.string().min(1, ZOD_MESSAGE.required).email(ZOD_MESSAGE.email),
9+
password: z.string().min(1, ZOD_MESSAGE.required),
1010
})
1111

12-
export const DEFAULT_INITIAL_VALUES: ILoginRequest = {
12+
export const DEFAULT_INITIAL_VALUES: LoginRequest = {
1313
email: '',
1414
password: '',
1515
}

packages/authentication/modules/access/useLogin/index.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client'
2+
13
import { useState } from 'react'
24

35
import {
@@ -16,19 +18,19 @@ import AuthApi from '../../../services/auth'
1618
import MfaApi from '../../../services/mfa'
1719
import { USER_API_KEY } from '../../../services/user'
1820
import {
19-
ILoginJWTResponse,
20-
ILoginMfaRequest,
21-
ILoginRequest,
22-
ILoginSimpleTokenResponse,
21+
LoginJWTResponse,
22+
LoginMfaRequest,
23+
LoginRequest,
24+
LoginSimpleTokenResponse,
2325
} from '../../../types/auth'
2426
import { isJWTResponse, isLoginMfaResponse } from '../../../utils/login'
2527
import { CODE_VALIDATION_INITIAL_VALUES, CODE_VALIDATION_SCHEMA } from '../../mfa/constants'
2628
import { useSimpleTokenUser } from '../../user'
2729
import { DEFAULT_INITIAL_VALUES, DEFAULT_VALIDATION_SCHEMA } from './constants'
28-
import { IUseLogin } from './types'
30+
import { UseLoginOptions } from './types'
2931

3032
const jwtSuccessHandler = (
31-
response: ILoginJWTResponse,
33+
response: LoginJWTResponse,
3234
cookieName: string,
3335
refreshCookieName: string,
3436
) => {
@@ -41,7 +43,7 @@ const jwtSuccessHandler = (
4143
}
4244

4345
const simpleTokenSuccessHandler = (
44-
response: ILoginSimpleTokenResponse,
46+
response: LoginSimpleTokenResponse,
4547
cookieName: string,
4648
onSuccess: () => void,
4749
) => {
@@ -62,21 +64,21 @@ const useLogin = ({
6264
refreshCookieName = REFRESH_COOKIE_NAME,
6365
ApiClass = AuthApi,
6466
enableFormApiErrors = true,
65-
}: IUseLogin = {}) => {
67+
}: UseLoginOptions = {}) => {
6668
const queryClient = useQueryClient()
6769
const [mfaEphemeralToken, setMfaEphemeralToken] = useState<string | null>(null)
6870
const { refetch: refetchUser } = useSimpleTokenUser({ options: { enabled: false } })
6971

7072
/*
7173
* Handles login success with the auth token in response
7274
*/
73-
async function handleLoginSuccess(response: ILoginJWTResponse | ILoginSimpleTokenResponse) {
75+
async function handleLoginSuccess(response: LoginJWTResponse | LoginSimpleTokenResponse) {
7476
if (isJWTResponse(tokenType, response)) {
7577
jwtSuccessHandler(response, cookieName, refreshCookieName)
7678
} else {
7779
simpleTokenSuccessHandler(response, cookieName, () => {
7880
// by invalidating the cache we force a reload of /v1/users/me and the state used by useUser hook
79-
queryClient.invalidateQueries(USER_API_KEY.getUser())
81+
queryClient.invalidateQueries({ queryKey: USER_API_KEY.getUser() })
8082
refetchUser()
8183
})
8284
}
@@ -89,7 +91,7 @@ const useLogin = ({
8991
})
9092

9193
const mutation = useMutation({
92-
mutationFn: (data: ILoginRequest) => ApiClass.login(data),
94+
mutationFn: (data: LoginRequest) => ApiClass.login(data),
9395
...loginOptions, // needs to be placed bellow all overridable options
9496
onError: (err, variables, context) => {
9597
loginOptions?.onError?.(err, variables, context)
@@ -113,7 +115,8 @@ const useLogin = ({
113115
mode: 'onBlur',
114116
})
115117

116-
const mfaMutation = useMutation((data: ILoginMfaRequest) => MfaApi.loginStep2(data), {
118+
const mfaMutation = useMutation({
119+
mutationFn: (data: LoginMfaRequest) => MfaApi.loginStep2(data),
117120
...mfaOptions, // needs to be placed bellow all overridable options
118121
onError: (err, variables, context) => {
119122
mfaOptions?.onError?.(err, variables, context)
@@ -122,6 +125,7 @@ const useLogin = ({
122125
}
123126
},
124127
onSuccess: (response, variables, context) => {
128+
// @ts-ignore BA-1206: fix typing
125129
handleLoginSuccess(response)
126130
mfaOptions?.onSuccess?.(response, variables, context)
127131
},

packages/authentication/modules/access/useLogin/types.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ import { UseMutationOptions } from '@tanstack/react-query'
44
import { z } from 'zod'
55

66
import AuthApi from '../../../services/auth'
7-
import { ICookieName, ILoginMfaRequest, ILoginRequest, LoginResponse } from '../../../types/auth'
7+
import {
8+
CustomCookieNames,
9+
LoginMfaRequest,
10+
LoginRequest,
11+
LoginResponse,
12+
} from '../../../types/auth'
813

914
type ApiClass = Pick<typeof AuthApi, 'login'>
1015

11-
export interface IUseLogin extends ICookieName {
16+
export interface UseLoginOptions extends CustomCookieNames {
1217
validationSchema?: z.ZodObject<z.ZodRawShape>
13-
defaultValues?: ILoginRequest
14-
loginOptions?: UseMutationOptions<LoginResponse, unknown, ILoginRequest, any>
15-
mfaOptions?: UseMutationOptions<LoginResponse, unknown, ILoginMfaRequest, any>
18+
defaultValues?: LoginRequest
19+
loginOptions?: UseMutationOptions<LoginResponse, unknown, LoginRequest, any>
20+
mfaOptions?: UseMutationOptions<LoginResponse, unknown, LoginMfaRequest, any>
1621
tokenType?: TokenTypes
1722
ApiClass?: ApiClass
1823
enableFormApiErrors?: boolean

packages/authentication/modules/access/useLogout/__tests__/useLogout.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ describe('useLogout hook', () => {
2727
result.current.logout()
2828

2929
expect(Cookies.remove).toHaveBeenCalled()
30-
expect(mockResetQueries).toHaveBeenCalledWith(USER_API_KEY.getUser())
31-
expect(mockResetQueries).toHaveBeenCalledWith(MFA_API_KEY.default)
30+
expect(mockResetQueries).toHaveBeenCalledWith({ queryKey: USER_API_KEY.getUser() })
31+
expect(mockResetQueries).toHaveBeenCalledWith({ queryKey: MFA_API_KEY.default })
3232
})
3333

3434
test('should call the onLogout callback if provided', async () => {

packages/authentication/modules/access/useLogout/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import Cookies from 'js-cookie'
1010

1111
import { MFA_API_KEY } from '../../../services/mfa'
1212
import { USER_API_KEY } from '../../../services/user'
13-
import { ILogoutOptions } from './types'
13+
import { UseLogoutOptions } from './types'
1414

1515
const useLogout = ({
1616
cookieName = ACCESS_COOKIE_NAME,
1717
refreshCookieName = REFRESH_COOKIE_NAME,
1818
onLogout,
1919
emitLogoutEvent = true,
20-
}: ILogoutOptions = {}) => {
20+
}: UseLogoutOptions = {}) => {
2121
const queryClient = useQueryClient()
2222

2323
const logout = () => {
2424
Cookies.remove(cookieName)
2525
Cookies.remove(refreshCookieName)
26-
queryClient.resetQueries(USER_API_KEY.getUser())
27-
queryClient.resetQueries(MFA_API_KEY.default)
26+
queryClient.resetQueries({ queryKey: USER_API_KEY.getUser() })
27+
queryClient.resetQueries({ queryKey: MFA_API_KEY.default })
2828
onLogout?.()
2929
if (emitLogoutEvent) {
3030
eventEmitter.emit(LOGOUT_EVENT)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ICookieName } from '../../../types/auth'
1+
import { CustomCookieNames } from '../../../types/auth'
22

3-
export interface ILogoutOptions extends ICookieName {
3+
export interface UseLogoutOptions extends CustomCookieNames {
44
onLogout?: () => void
55
emitLogoutEvent?: boolean
66
}

0 commit comments

Comments
 (0)