Skip to content

Commit 0bf2db7

Browse files
committed
moved setcookie to login and simplify logout function
1 parent 9523d42 commit 0bf2db7

File tree

5 files changed

+4
-24
lines changed

5 files changed

+4
-24
lines changed

pages/airways.tsx

-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import airplaneDining from "@/assets/img/airways/airplaneDining.jpg";
1111
import { FlightCalendar } from "@/components/ui/airwayscomponents/flightCalendar";
1212
import { AnimatePresence } from "framer-motion";
1313
import LoginHomePage from "@/components/LoginHomePage";
14-
import { setCookie } from "cookies-next";
1514
import { Toaster } from "@/components/ui/toaster";
1615

1716
import AirlineHero from "@/components/ui/airwayscomponents/airlineHero";
@@ -56,10 +55,6 @@ export default function Airways() {
5655

5756
function handleLogout() {
5857
logoutUser();
59-
const context: any = ldclient?.getContext();
60-
context.user.tier = null;
61-
ldclient?.identify(context);
62-
setCookie("ldcontext", context);
6358
}
6459

6560
function bookTrip() {

pages/bank.tsx

-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { CreditAccount } from "@/components/ui/bankcomponents/creditview";
55
import { MorgtgageAccount } from "@/components/ui/bankcomponents/mortgageview";
66
import { useFlags, useLDClient } from "launchdarkly-react-client-sdk";
77
import { checkData } from "@/lib/checkingdata";
8-
import { setCookie } from "cookies-next";
98
import LoginContext from "@/utils/contexts/login";
109
import { FederatedCheckingAccount } from "@/components/ui/bankcomponents/federatedChecking";
1110
import { FederatedCreditAccount } from "@/components/ui/bankcomponents/federatedCredit";
@@ -94,10 +93,6 @@ export default function Bank() {
9493

9594
function handleLogout() {
9695
logoutUser();
97-
const context: any = ldclient?.getContext();
98-
context.user.tier = null;
99-
ldclient?.identify(context);
100-
setCookie("ldcontext", context);
10196
}
10297

10398
const bankingServicesArr = [

pages/investment.tsx

-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { useContext } from "react";
22
import { motion } from "framer-motion";
33
import { Toaster } from "@/components/ui/toaster";
4-
import { useLDClient } from "launchdarkly-react-client-sdk";
54
import NavBar from "@/components/ui/navbar";
65
import { AnimatePresence } from "framer-motion";
76
import LoginHomePage from "@/components/LoginHomePage";
8-
import { setCookie } from "cookies-next";
97
import LoginContext from "@/utils/contexts/login";
108
import InvestmentAccountHeader from "@/components/ui/investmentcomponents/InvestmentAccountHeader";
119

@@ -21,16 +19,10 @@ import RecentTradesCard from "@/components/ui/investmentcomponents/RecentTradesC
2119
export default function Investment() {
2220
const { isLoggedIn, logoutUser } = useContext(LoginContext);
2321

24-
const ldclient = useLDClient();
25-
2622
//TODO: either use this or the one in login.js
2723
//TODO: move this into navbar
2824
function handleLogout() {
2925
logoutUser();
30-
const context: any = ldclient?.getContext();
31-
context.user.tier = null;
32-
ldclient?.identify(context);
33-
setCookie("ldcontext", context);
3426
}
3527

3628
const cardStyle = "rounded-lg shadow-lg p-5 sm:p-5 bg-white";

pages/marketplace.tsx

-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { ReactSearchAutocomplete } from "react-search-autocomplete";
1212
import { AnimatePresence } from "framer-motion";
1313
import { Toaster } from "@/components/ui/toaster";
1414
import LoginContext from "@/utils/contexts/login";
15-
import { setCookie } from "cookies-next";
1615

1716
export default function Marketplace() {
1817
const [headerLabel, setHeaderLabel] = useState<string>("");
@@ -264,10 +263,6 @@ export default function Marketplace() {
264263

265264
function handleLogout() {
266265
logoutUser();
267-
const context: any = LDClient?.getContext();
268-
context.user.tier = null;
269-
LDClient?.identify(context);
270-
setCookie("ldcontext", context);
271266
}
272267

273268
useEffect(() => {

utils/contexts/login.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const LoginProvider = ({ children }) => {
3838
context.audience.key = uuidv4().slice(0, 10);
3939
context.user.launchclub = launchClubStatus;
4040
await client?.identify(context);
41+
setCookie("ld-context", context);
4142
setIsLoggedIn(true);
4243
setUser(user);
4344
setEmail(email);
@@ -57,14 +58,16 @@ export const LoginProvider = ({ children }) => {
5758
setLaunchClubStatus("standard");
5859
const context = await createAnonymousContext();
5960
await client?.identify(context);
61+
setCookie("ld-context", context);
6062
console.log("Anonymous User", context);
6163
};
6264

6365
const createAnonymousContext = async () => {
6466
return {
6567
"kind": "multi",
6668
"user": {
67-
"anonymous": true
69+
"anonymous": true,
70+
"tier":null
6871
},
6972
"device": {
7073
"key": device,

0 commit comments

Comments
 (0)