Skip to content

Commit

Permalink
Merge pull request #20 from GuiMoraesDev/chore/addSessionCallAfterUse…
Browse files Browse the repository at this point in the history
…rSignUp

chore: add session call after user sign up
  • Loading branch information
GuiMoraesDev authored Sep 2, 2022
2 parents 46ce95c + 896f571 commit 69cc5d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 1 addition & 6 deletions src/services/users.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import { UserProps } from '@types';

import api from './api';

interface SignUpSuccessfulProps {
user: UserProps;
token: string;
};

export interface PostNewUserParams {
first_name: UserProps['first_name'];
last_name: UserProps['last_name'];
Expand All @@ -15,7 +10,7 @@ export interface PostNewUserParams {
}

export const postNewUser = async (data: PostNewUserParams) => {
const response = await api.post<SignUpSuccessfulProps>('/users/new', data);
const response = await api.post<UserProps>('/users/new', data);

return response.data;
};
8 changes: 7 additions & 1 deletion src/views/Sign/signup.index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Input from 'components/Input';

import logYupErrors from 'helpers/logYupErrors';

import { postNewSession } from 'services/sessions.api';
import { postNewUser, PostNewUserParams } from 'services/users.api';

import useSignValidation from './hooks/useSignValidation';
Expand All @@ -27,7 +28,12 @@ const SignIn = (): JSX.Element => {
setIsLoading(true);

try {
const { user, token } = await postNewUser(values);
await postNewUser(values);

const { user, token } = await postNewSession({
email: values.email,
password: values.password,
});

nookies.set(null, 'user', JSON.stringify(user));
nookies.set(null, 'token', JSON.stringify(token));
Expand Down

1 comment on commit 69cc5d7

@vercel
Copy link

@vercel vercel bot commented on 69cc5d7 Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.