فهرست منبع

fix: register store token

Nicolas Meienberger 2 سال پیش
والد
کامیت
e8d7edbe57
2فایلهای تغییر یافته به همراه13 افزوده شده و 3 حذف شده
  1. 9 1
      packages/dashboard/src/modules/Auth/containers/Onboarding.tsx
  2. 4 2
      scripts/common.sh

+ 9 - 1
packages/dashboard/src/modules/Auth/containers/Onboarding.tsx

@@ -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 {

+ 4 - 2
scripts/common.sh

@@ -81,10 +81,12 @@ function kill_watcher() {
         # If multiline kill each pid
         if [[ $watcher_pid == *" "* ]]; then
             for pid in $watcher_pid; do
-                kill -9 "$pid"
+                # shellcheck disable=SC2086
+                kill -9 $pid
             done
         else
-            kill -9 "$watcher_pid"
+            # shellcheck disable=SC2086
+            kill -9 $watcher_pid
         fi
     fi
 }