Skip to content

Commit 8ed4e42

Browse files
committed
fixed registration bug
1 parent 7017fb7 commit 8ed4e42

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

src/features/auth/api/authApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AuthCredentials } from "../model/types";
33

44
export const authApiSlice = apiSlice.injectEndpoints({
55
endpoints: (builder) => ({
6-
register: builder.mutation<TokenPair, AuthCredentials>({
6+
register: builder.mutation<void, AuthCredentials>({
77
query: (credentials: AuthCredentials) => ({
88
url: "/users/register",
99
method: "POST",

src/features/auth/lib/mapAuthError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ export const mapAuthApiError = (
7575

7676
return {
7777
title: "Не удалось выполнить запрос",
78-
description: "Попробуйте повторить попытку или обратитесь к админу.",
78+
description: "Попробуйте еще раз.",
7979
};
8080
};

src/features/auth/model/authSlice.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ const slice = createSlice({
3232
.addMatcher(authApiSlice.endpoints.login.matchFulfilled, (state, { payload }) =>
3333
applyTokens(state, payload),
3434
)
35-
.addMatcher(authApiSlice.endpoints.register.matchFulfilled, (state, { payload }) =>
36-
applyTokens(state, payload),
37-
)
3835
.addMatcher(userApiSlice.endpoints.getMe.matchFulfilled, (state, { payload }) => {
3936
state.user = payload;
4037
});

src/features/auth/ui/RegisterForm/RegisterForm.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRegisterMutation } from "features/auth/api/authApi";
1+
import { useLoginMutation, useRegisterMutation } from "features/auth/api/authApi";
22
import { registrationStruct } from "features/auth/model/authStruct";
33
import { mapAuthApiError, mapValidationError } from "features/auth/lib/mapAuthError";
44
import { FormEvent, FormEventHandler, useState } from "react";
@@ -22,7 +22,10 @@ export const RegisterForm = ({ onStatusChange }: RegisterFormProps) => {
2222

2323
const navigate = useNavigate();
2424

25-
const [register, { isLoading }] = useRegisterMutation();
25+
const [register, { isLoading: isRegisterLoading }] = useRegisterMutation();
26+
const [login, { isLoading: isLoginLoading }] = useLoginMutation();
27+
28+
const isLoading = isLoginLoading || isRegisterLoading;
2629

2730
const onSubmit: FormEventHandler<HTMLFormElement> = async (e: FormEvent<HTMLFormElement>) => {
2831
e.preventDefault();
@@ -41,9 +44,13 @@ export const RegisterForm = ({ onStatusChange }: RegisterFormProps) => {
4144

4245
try {
4346
await register(result).unwrap();
47+
await login({ nickname, password }).unwrap();
48+
4449
onStatusChange?.(null);
50+
4551
navigate(AppRoutes.INDEX);
4652
} catch (err) {
53+
console.log(err);
4754
const payload = mapAuthApiError(err);
4855
onStatusChange?.(payload);
4956
}

src/pages/auth/ui/AuthPage.module.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
align-items: center;
55
justify-content: center;
66
gap: 1.5em;
7-
min-height: 100%;
87
}
98

109
.statusBanner {

0 commit comments

Comments
 (0)