fix browser refresh redirecting to /chat/new (#210)
This commit is contained in:
@@ -3,7 +3,6 @@ const Conversation = require('./schema/convoSchema');
|
||||
const { getMessages, deleteMessages } = require('./Message');
|
||||
|
||||
const getConvo = async (user, conversationId) => {
|
||||
console.log('getConvo -> userId', user);
|
||||
try {
|
||||
return await Conversation.findOne({ user, conversationId }).exec();
|
||||
} catch (error) {
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
TLoginUser
|
||||
} from '~/data-provider';
|
||||
import { useNavigate, useLocation } from 'react-router-dom';
|
||||
import store from '~/store';
|
||||
|
||||
export type TAuthContext = {
|
||||
user: TUser | undefined,
|
||||
@@ -47,8 +46,6 @@ const AuthContextProvider = ({ children }: { children: ReactNode }) => {
|
||||
|
||||
const location = useLocation();
|
||||
|
||||
const { newConversation } = store.useConversation();
|
||||
|
||||
const setUserContext = (userContext: TUserContext) => {
|
||||
const { token, isAuthenticated, user, redirect } = userContext;
|
||||
if(user) {
|
||||
@@ -110,7 +107,7 @@ const AuthContextProvider = ({ children }: { children: ReactNode }) => {
|
||||
const tokenFromCookie = getCookieValue('token');
|
||||
if (tokenFromCookie) {
|
||||
// debugger;
|
||||
setUserContext({ token: tokenFromCookie, isAuthenticated: true, user: userQuery.data, redirect: '/chat/new' })
|
||||
setUserContext({ token: tokenFromCookie, isAuthenticated: true, user: userQuery.data })
|
||||
}
|
||||
else {
|
||||
navigate('/login');
|
||||
|
||||
Reference in New Issue
Block a user