Skip to content

Commit

Permalink
feat: posthogv2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sampiiiii committed Apr 14, 2024
1 parent a507419 commit e18e2b5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 54 deletions.
25 changes: 0 additions & 25 deletions apps/forge/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,6 @@
<meta property="og:type" content="website"/>
<meta property="og:url" content="https://iforge.sheffield.ac.uk"/>

<script>
!function (t, e) {
var o, n, p, r;
e.__SV || (window.posthog = e, e._i = [], e.init = function (i, s, a) {
function g(t, e) {
var o = e.split(".");
2 == o.length && (t = t[o[0]], e = o[1]), t[e] = function () {
t.push([e].concat(Array.prototype.slice.call(arguments, 0)))
}
}

(p = t.createElement("script")).type = "text/javascript", p.async = !0, p.src = s.api_host + "/static/array.js", (r = t.getElementsByTagName("script")[0]).parentNode.insertBefore(p, r);
var u = e;
for (void 0 !== a ? u = e[a] = [] : a = "posthog", u.people = u.people || [], u.toString = function (t) {
var e = "posthog";
return "posthog" !== a && (e += "." + a), t || (e += " (stub)"), e
}, u.people.toString = function () {
return u.toString(1) + ".people (stub)"
}, o = "capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys onSessionId".split(" "), n = 0; n < o.length; n++) g(u, o[n]);
e._i.push([i, s, a])
}, e.__SV = 1)
}(document, window.posthog || []);
posthog.init('phc_XIzxR3RXcdmcyMPJCCnQFtxoL0gRshzEXo4kM925LvA', {api_host: 'https://web-mkc4o00.sampiiiii.dev'})
</script>


</head>
<body>
Expand Down
1 change: 1 addition & 0 deletions apps/forge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"memoize-one": "^6.0.0",
"next-themes": "^0.2.1",
"postcss": "^8.4.38",
"posthog-js": "^1.121.2",
"react": "^18.2.0",
"react-cookie": "^6.1.3",
"react-day-picker": "^8.10.0",
Expand Down
58 changes: 29 additions & 29 deletions apps/forge/src/hooks/useLogout.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { AppDispatch, persistor } from "@/redux/store.ts";
import { authActions } from "@/redux/auth.slice.ts";
import { userActions } from "@/redux/user.slice.ts";
import {AppDispatch, persistor} from "@/redux/store.ts";
import {authActions} from "@/redux/auth.slice.ts";
import {userActions} from "@/redux/user.slice.ts";
import axiosInstance from "@/api/axiosInstance.ts";
import { toast } from "sonner";
import { useNavigate } from "@tanstack/react-router";
import { useAuth } from "@/components/auth-provider";
import { useDispatch } from "react-redux";
import {toast} from "sonner";
import {useNavigate} from "@tanstack/react-router";
import {useAuth} from "@/components/auth-provider";
import {useDispatch} from "react-redux";
import axios from "axios";

export const useLogout = () => {
const dispatch: AppDispatch = useDispatch();
const auth = useAuth();
const navigate = useNavigate();
const dispatch: AppDispatch = useDispatch();
const auth = useAuth();
const navigate = useNavigate();

return async () => {
try {
await axiosInstance.post("/authentication/logout");
await persistor.purge();
dispatch(userActions.clearUser());
dispatch(authActions.onLogout());
auth.logout();
toast.success("Logged out successfully.");
await navigate({ to: "/" });
} catch (error) {
if (axios.isAxiosError(error) && error.response?.status === 409) {
await navigate({ to: "/" });
return;
}
console.error("Logout failed:", error);
toast.error("Logout failed.");
await navigate({ to: "/" });
}
};
return async () => {
try {
await axiosInstance.post("/authentication/logout");
await persistor.purge();
dispatch(userActions.clearUser());
dispatch(authActions.onLogout());
auth.logout();
toast.success("Logged out successfully.");
await navigate({to: "/"});
} catch (error) {
if (axios.isAxiosError(error) && error.response?.status === 409) {
await navigate({to: "/"});
return;
}
console.error("Logout failed:", error);
toast.error("Logout failed.");
await navigate({to: "/"});
}
};
};
3 changes: 3 additions & 0 deletions apps/forge/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {routeTree} from "@/routeTree.gen.ts";
import {Toaster} from "@ui/components/ui/sonner.tsx";
import {AuthProvider, useAuth} from "@/components/auth-provider";
import LoadingView from "@/components/loading-view";
import posthog from 'posthog-js'


// Begin Router
const queryClient = new QueryClient();
Expand All @@ -40,6 +42,7 @@ declare module "@tanstack/react-router" {

function InnerApp() {
const auth = useAuth()
posthog.init('phc_XIzxR3RXcdmcyMPJCCnQFtxoL0gRshzEXo4kM925LvA', {api_host: 'https://web-mkc4o00.sampiiiii.dev'})
return <RouterProvider router={router} context={{auth}}/>
}

Expand Down
18 changes: 18 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e18e2b5

Please sign in to comment.