From 96e2fadf81108c18d1027a81b284de069b854577 Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Tue, 1 Jul 2025 20:45:48 +0200 Subject: [PATCH 1/9] Add login --- .env.example | 6 +- src/components/Header/Navbar.component.tsx | 38 ++++- .../User/CustomerAccount.component.tsx | 61 ++++++++ src/components/User/UserLogin.component.tsx | 85 +++++++++++ src/components/User/withAuth.component.tsx | 25 ++++ src/pages/logg-inn.tsx | 15 ++ src/pages/min-konto.tsx | 16 +++ src/utils/apollo/ApolloClient.js | 23 ++- src/utils/auth.ts | 134 ++++++++++++++++++ src/utils/gql/GQL_MUTATIONS.ts | 20 +++ src/utils/gql/GQL_QUERIES.ts | 16 +++ 11 files changed, 431 insertions(+), 8 deletions(-) create mode 100644 src/components/User/CustomerAccount.component.tsx create mode 100644 src/components/User/UserLogin.component.tsx create mode 100644 src/components/User/withAuth.component.tsx create mode 100644 src/pages/logg-inn.tsx create mode 100644 src/pages/min-konto.tsx create mode 100644 src/utils/auth.ts diff --git a/.env.example b/.env.example index aad4da7ae..d1903cf48 100644 --- a/.env.example +++ b/.env.example @@ -4,4 +4,8 @@ NEXT_PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL="https://res.cloudinary.com/placeholder- NEXT_PUBLIC_PLACEHOLDER_LARGE_IMAGE_URL="https://via.placeholder.com/600" NEXT_PUBLIC_ALGOLIA_APP_ID = "changeme" NEXT_PUBLIC_ALGOLIA_PUBLIC_API_KEY = "changeme" -NODE_ENV="development" \ No newline at end of file +NODE_ENV="development" +NEXT_PUBLIC_AUTH_TOKEN_SS_KEY="auth-token" +NEXT_PUBLIC_REFRESH_TOKEN_LS_KEY="refresh-token" +NEXT_PUBLIC_SESSION_TOKEN_LS_KEY="session-token" +NEXT_PUBLIC_AUTH_KEY_TIMEOUT="300000" diff --git a/src/components/Header/Navbar.component.tsx b/src/components/Header/Navbar.component.tsx index 4d498ce81..a27acc232 100644 --- a/src/components/Header/Navbar.component.tsx +++ b/src/components/Header/Navbar.component.tsx @@ -1,5 +1,6 @@ import Link from 'next/link'; - +import { useEffect, useState } from 'react'; +import { hasCredentials } from '../../utils/auth'; import Cart from './Cart.component'; import AlgoliaSearchBox from '../AlgoliaSearch/AlgoliaSearchBox.component'; import MobileSearch from '../AlgoliaSearch/MobileSearch.component'; @@ -9,6 +10,12 @@ import MobileSearch from '../AlgoliaSearch/MobileSearch.component'; * Includes mobile menu. */ const Navbar = () => { + const [loggedIn, setLoggedIn] = useState(false); + + useEffect(() => { + setLoggedIn(hasCredentials()); + }, []); + return (