Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/dashboard/app/providers/posthog-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import { PostHogProvider as PHProvider } from 'posthog-js/react';
export function PostHogProvider({ children }: { children: React.ReactNode }) {
useEffect(() => {
const posthogKey = process.env.NEXT_PUBLIC_POSTHOG_KEY;
const isProd = process.env.NODE_ENV === 'production';
const enableInDev = process.env.NEXT_PUBLIC_ENABLE_POSTHOG_IN_DEV === 'true';

// Only initialize PostHog if we have a valid key
if (posthogKey) {
// Only initialize PostHog if we have a valid key and it's production
// or explicitly enabled for development.
if (posthogKey && (isProd || enableInDev)) {
posthog.init(posthogKey, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com',
person_profiles: 'identified_only', // or 'always' to create profiles for anonymous users as well
capture_pageview: false, // Disable automatic pageview capture, as we capture manually
person_profiles: 'identified_only',
capture_pageview: false,
});
}
}, []);
Expand Down
5 changes: 5 additions & 0 deletions app/dashboard/app/signin/auth-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export function AuthForm() {
}

const checkAuth = async () => {
// If there is no session cookie, skip calling the API to avoid 401 spam in dev
if (typeof document !== 'undefined' && !document.cookie.includes('session_id=')) {
setIsCheckingAuth(false);
return;
}
try {
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/opsboard/users/me`, {
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/app/signin/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { GithubIcon as Github, Loading03Icon as Loader } from 'hugeicons-react';
import { MagicWand01Icon as WandSparkles } from 'hugeicons-react';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import posthog from 'posthog-js';
// posthog is not required directly in this file; remove unused import to prevent bundling warnings
import { useState, useEffect } from 'react';
import { toast } from '@/components/ui/use-toast';

Expand Down
4 changes: 4 additions & 0 deletions app/dashboard/app/simple-login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const SimpleLoginPageDev = () => {
const authBaseUrl = `${apiUrl}/auth`;

const checkAuthAndFetchDetails = async () => {
// Avoid unnecessary 401s in local mode: if there is no session cookie, skip the check
if (typeof document !== 'undefined' && !document.cookie.includes('session_id=')) {
return false;
}
const lastLoginMethod = localStorage.getItem('loginMethodUsed') as LoginType | null;
if (loginMethodUsed !== lastLoginMethod) {
setLoginMethodUsed(lastLoginMethod);
Expand Down