Skip to content

Commit 009e84d

Browse files
authored
Merge pull request #83 from jpcmf/improvement/auth-context-cookie-maxage
Improvement/auth context cookie maxage
2 parents 87db1c6 + f995f42 commit 009e84d

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

src/components/Header/Profile.tsx

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import { useContext } from "react";
22
import { RiLogoutCircleLine } from "react-icons/ri";
3-
import { Box, Flex, Text, Menu, Avatar, MenuList, MenuItem, MenuButton } from "@chakra-ui/react";
3+
import {
4+
Box,
5+
Flex,
6+
Text,
7+
Menu,
8+
Avatar,
9+
MenuList,
10+
MenuItem,
11+
MenuButton,
12+
MenuDivider,
13+
MenuGroup
14+
} from "@chakra-ui/react";
415

516
import { AuthContext } from "@/contexts/AuthContext";
617

@@ -27,18 +38,27 @@ export function Profile({ showProfileData = true }: ProfileProps) {
2738
</MenuButton>
2839

2940
<MenuList bg="gray.900" borderColor="gray.800">
30-
<MenuItem
31-
icon={<RiLogoutCircleLine size={16} />}
32-
onClick={signOut}
33-
color="gray.600"
34-
bg="gray.900"
35-
_hover={{ color: "white" }}
36-
>
37-
Logout
38-
</MenuItem>
39-
<MenuItem color="gray.600" bg="gray.900" _hover={{ color: "white" }}>
40-
{user?.about}
41-
</MenuItem>
41+
<MenuGroup title="Minha conta">
42+
<MenuItem color="gray.600" bg="gray.900" _hover={{ color: "white" }}>
43+
{user?.about}
44+
</MenuItem>
45+
<MenuItem color="gray.600" bg="gray.900" _hover={{ color: "white" }}>
46+
My Account
47+
</MenuItem>
48+
<MenuItem color="gray.600" bg="gray.900" _hover={{ color: "white" }}>
49+
Payments{" "}
50+
</MenuItem>
51+
<MenuDivider />
52+
<MenuItem
53+
icon={<RiLogoutCircleLine size={16} />}
54+
onClick={signOut}
55+
color="gray.600"
56+
bg="gray.900"
57+
_hover={{ color: "white" }}
58+
>
59+
Logout
60+
</MenuItem>
61+
</MenuGroup>
4262
</MenuList>
4363
</Menu>
4464
</Flex>

src/contexts/AuthContext.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Router from "next/router";
2-
import { destroyCookie, parseCookies, setCookie } from "nookies";
32
import { createContext, useEffect, useState } from "react";
3+
import { destroyCookie, parseCookies, setCookie } from "nookies";
44

55
import { signInRequest, userMe } from "../services/auth";
66

@@ -48,18 +48,18 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
4848
const { user, jwt } = await signInRequest({ email, password });
4949

5050
setCookie(undefined, "nextauth.token", jwt, {
51-
// maxAge: 60 * 60 * 1 // 1 hour
52-
maxAge: 180 // 3 minutes
51+
maxAge: 60 * 60 * 1 // 1 hour
52+
// maxAge: 60 * 60 * 24 * 1 // 1 day
5353
});
5454

5555
setUser(user);
56-
57-
console.log("user...", user);
56+
console.table(user);
5857

5958
Router.push("/dashboard");
6059
}
6160

6261
function signOut() {
62+
setUser(null);
6363
destroyCookie(undefined, "nextauth.token");
6464
Router.push("/auth/signin");
6565
}

0 commit comments

Comments
 (0)