|
@@ -1,3 +1,4 @@
|
|
|
+import { useApolloClient } from '@apollo/client';
|
|
|
import { useToast } from '@chakra-ui/react';
|
|
|
import React, { useState } from 'react';
|
|
|
import { useRegisterMutation } from '../../../generated/graphql';
|
|
@@ -5,6 +6,7 @@ import AuthFormLayout from '../components/AuthFormLayout';
|
|
|
import RegisterForm from '../components/RegisterForm';
|
|
|
|
|
|
const Onboarding: React.FC = () => {
|
|
|
+ const client = useApolloClient();
|
|
|
const toast = useToast();
|
|
|
const [register] = useRegisterMutation({ refetchQueries: ['Me'] });
|
|
|
const [loading, setLoading] = useState(false);
|
|
@@ -24,7 +26,13 @@ const Onboarding: React.FC = () => {
|
|
|
const handleRegister = async (values: { email: string; password: string }) => {
|
|
|
try {
|
|
|
setLoading(true);
|
|
|
- await register({ variables: { input: { username: values.email, password: values.password } } });
|
|
|
+ const { data } = await register({ variables: { input: { username: values.email, password: values.password } } });
|
|
|
+
|
|
|
+ if (data?.register?.token) {
|
|
|
+ localStorage.setItem('token', data.register.token);
|
|
|
+ }
|
|
|
+
|
|
|
+ await client.refetchQueries({ include: ['Me'] });
|
|
|
} catch (error) {
|
|
|
handleError(error);
|
|
|
} finally {
|