Skip to content

Commit

Permalink
Need to refresh to file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Gessmass committed Nov 8, 2024
1 parent 04d65d2 commit f46c5f9
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 39 deletions.
2 changes: 2 additions & 0 deletions backend/src/resolvers/FileResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class FileResolver {
@Query(() => [File])
async getUserAccessSharedFiles(@Ctx() context: Context) {

console.log(context.id)

return await File.createQueryBuilder("file")
.leftJoin("file.users_with_access", "user")
.where("user.id = :userId", {userId: context.id})
Expand Down
12 changes: 4 additions & 8 deletions backend/src/resolvers/UserResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class UserResolver {
return "You have successfully signed up!"
}

@Mutation(() => UserInfo)
@Mutation(() => String)
async login(
@Arg("email") emailFromClient: string,
@Arg("password") passwordFromClient: string,
Expand Down Expand Up @@ -93,13 +93,7 @@ class UserResolver {

context.res.setHeader("Set-Cookie", serializedCookie);

return {
email: userFromDB.email,
role: userFromDB.role,
firstname: userFromDB.firstname,
lastname: userFromDB.lastname,
isLoggedIn: true,
};
return "User logged in";

} catch (err) {
if (err instanceof EntityNotFoundError || err instanceof AuthenticationError) {
Expand Down Expand Up @@ -148,6 +142,8 @@ class UserResolver {
throw new Error("User not authenticated");
}

console.log(context.id)

const user = await User.findOne({
where: {id: context.id},
relations: ['uploads', 'uploads.files'],
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import PricingPage from "./pages/PricingPage.tsx";
import BillingPage from "./pages/BillingPage.tsx";
import VisitorDownloadPage from "./pages/VisitorDownloadPage.tsx";
import {FC} from "react";
import {UserProvider, useUserContext} from "./context/UserContext.tsx";

interface ProtectedRouteProps {
isLoggedIn: boolean;
Expand All @@ -28,14 +27,13 @@ const ProtectedRoute = ({isLoggedIn, children}: ProtectedRouteProps) => {

const App: FC = () => {
return (
<UserProvider>
<MainLayout/>
</UserProvider>
// <UserProvider>
<MainLayout/>
// </UserProvider>
);
};

const MainLayout: FC = () => {
const {isLoggedIn} = useUserContext()

const router = createBrowserRouter([
{path: "/", element: <LandingPage/>},
Expand All @@ -56,7 +54,7 @@ const MainLayout: FC = () => {
children: [
{
index: true,
element: <ProtectedRoute isLoggedIn={isLoggedIn}><Dashboard/></ProtectedRoute>
element: <ProtectedRoute isLoggedIn={true}><Dashboard/></ProtectedRoute>
},
{path: "settings", element: <SettingsPage/>},
{path: "billing", element: <BillingPage/>},
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/components/Signin/SignInForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ import {LOGIN_MUTATION} from "../../graphql/mutations.ts";
import {useNavigate} from 'react-router-dom'
import {ApolloError, useMutation} from "@apollo/client";
import styled from "@emotion/styled";
import {useUserContext} from "../../context/UserContext.tsx";

const {Item} = Form

const SignInForm: React.FC = () => {
const [notifApi, contextHolder] = notification.useNotification()
const navigate = useNavigate()
const {setUser} = useUserContext()


const [login, {loading, error}] = useMutation(LOGIN_MUTATION, {
onCompleted: (data) => {
setUser(data.login)
navigate("/dashboard");
},
onError: (error: ApolloError) => {
Expand Down
11 changes: 1 addition & 10 deletions frontend/src/components/user/UserLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,12 @@ import {DashboardOutlined, DollarOutlined, LogoutOutlined, SettingOutlined} from
import {Link, Outlet, useNavigate} from "react-router-dom";
import {ApolloError, useMutation} from '@apollo/client';
import {LOGOUT} from "../../graphql/mutations.ts";
import {useUserContext} from "../../context/UserContext.tsx";

const UserLayout: FC = () => {
const navigate = useNavigate();
const {setUser, firstname} = useUserContext()

const [logout] = useMutation(LOGOUT, {
onCompleted: () => {
setUser({
isLoggedIn: false,
role: '',
firstname: '',
lastname: '',
email: '',
})
navigate('/');
},
onError: (err: ApolloError) => {
Expand Down Expand Up @@ -66,7 +57,7 @@ const UserLayout: FC = () => {
backgroundColor: '#fde3cf',
color: '#f56a00',
cursor: 'pointer'
}}>{firstname.charAt(0).toUpperCase()}</Avatar>
}}>U</Avatar>
</Dropdown>
</HeaderContainer>
<Outlet/>
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/context/UserContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {createContext, FC, ReactNode, useContext, useEffect, useState} from 'react';
import React, {createContext, FC, ReactNode, useContext, useState} from 'react';

interface UserContextType {
isLoggedIn: boolean;
Expand All @@ -21,10 +21,6 @@ export const UserProvider: FC<{ children: ReactNode }> = ({children}) => {
setUser: (userData) => setUser((prev) => ({...prev, ...userData})),
});

useEffect(() => {
console.log(user)
}, [user]);

return <UserContext.Provider value={user}>{children}</UserContext.Provider>;
};

Expand Down
8 changes: 1 addition & 7 deletions frontend/src/graphql/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ export const SIGN_UP_USER = gql`

export const LOGIN_MUTATION = gql`
mutation Login($email: String!, $password: String!) {
login(email: $email, password: $password) {
email
role
firstname
lastname
isLoggedIn
}
login(email: $email, password: $password)
}
`;

Expand Down

0 comments on commit f46c5f9

Please sign in to comment.