Skip to content
Merged
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
4 changes: 1 addition & 3 deletions app/api/auth/[...nextauth]/auth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import GoogleProvider from 'next-auth/providers/google';
import TwitterProvider from 'next-auth/providers/twitter';
import CredentialsProvider from 'next-auth/providers/credentials';
import { AuthService } from '@/services/auth.service';
import { AuthSharingService } from '@/services/auth-sharing.service';

// Debug flag - set to true to enable detailed authentication logging
const DEBUG_AUTH = true;
Expand Down Expand Up @@ -70,7 +69,7 @@ export const authOptions: NextAuthOptions = {
},
async authorize(credentials, req) {
try {
// If we have an authToken from the shared cookie, use that directly
// Email verification and MFA sign in with an already-issued token.
if (credentials?.authToken) {
try {
// Fetch user data using the provided authToken
Expand All @@ -83,7 +82,6 @@ export const authOptions: NextAuthOptions = {
authToken: credentials.authToken,
};
} catch (error) {
AuthSharingService.removeSharedAuthToken();
return promptInvalidCredentials();
}
}
Expand Down
45 changes: 0 additions & 45 deletions app/api/auth/logout/route.ts

This file was deleted.

88 changes: 0 additions & 88 deletions components/AuthSharingWrapper.tsx

This file was deleted.

30 changes: 30 additions & 0 deletions components/LegacyAuthCookieCleanup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use client';

import Cookies from 'js-cookie';
import { useEffect } from 'react';

//
// FIXME: Remove this file once the legacy auth cookie is no longer valid (14 days after deploy)

Check warning on line 7 in components/LegacyAuthCookieCleanup.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Take the required action to fix the issue indicated by this comment.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AaH0tnCH5Rlopup0Do9e&open=AaH0tnCH5Rlopup0Do9e&pullRequest=1316
//
// The retired cross-app auth sharing kept the API token in a script-readable
// cookie on the parent domain, where every subdomain could read it. Each write
// set a 14-day expiry, so this can be deleted two weeks after deploy.
const LEGACY_AUTH_COOKIE = (() => {
switch (process.env.NEXT_PUBLIC_VERCEL_ENV) {
case 'production':
return { name: 'prod.researchhub.auth.token', domain: '.researchhub.com' };
case 'preview':
case 'development':
return { name: 'stg.researchhub.auth.token', domain: '.staging.researchhub.com' };
default:
return { name: 'local.researchhub.auth.token', domain: 'localhost' };
}
})();

export function LegacyAuthCookieCleanup() {
useEffect(() => {
Cookies.remove(LEGACY_AUTH_COOKIE.name, { domain: LEGACY_AUTH_COOKIE.domain, path: '/' });
}, []);

return null;
}
4 changes: 2 additions & 2 deletions components/You/YouMoreCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { useChangelogSeen } from '@/components/changelog/useChangelogSeen';
import { BaseMenu } from '@/components/ui/form/BaseMenu';
import { ResearchCoinIcon } from '@/components/ui/icons/ResearchCoinIcon';
import { useVerification } from '@/contexts/VerificationContext';
import { AuthSharingService } from '@/services/auth-sharing.service';
import { signOutUser } from '@/utils/auth';
import type { User } from '@/types/user';
import { cn } from '@/utils/styles';
import { CurrencySwitch } from './CurrencySwitch';
Expand Down Expand Up @@ -245,7 +245,7 @@ export function YouAccountCard({
</RowLink>
<button
type="button"
onClick={() => AuthSharingService.signOutFromBothApps()}
onClick={() => signOutUser()}
className={YOU_ROW}
data-testid="user-menu-signout"
>
Expand Down
8 changes: 2 additions & 6 deletions components/events/catalyst/CatalystLoggedInBody.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use client';

import { useRouter } from 'next/navigation';
import { signOut } from 'next-auth/react';
import AnalyticsService from '@/services/analytics.service';
import { AuthSharingService } from '@/services/auth-sharing.service';
import { signOutUser } from '@/utils/auth';
import { CATALYST_NYC_EVENT, formatCredit } from './constants';

const { footer, loggedIn, creditAmount, route } = CATALYST_NYC_EVENT;
Expand All @@ -23,9 +21,7 @@ export function CatalystLoggedInBody({
const isMobile = variant === 'mobile';

const handleSignOut = () => {
AuthSharingService.removeSharedAuthToken();
AnalyticsService.clearUserSession();
signOut({ callbackUrl: route });
void signOutUser(route);
};

return (
Expand Down
4 changes: 2 additions & 2 deletions components/menus/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { BaseMenu, BaseMenuItem } from '@/components/ui/form/BaseMenu';
import { VerifiedBadge } from '@/components/ui/VerifiedBadge';
import { ResearchCoinIcon } from '@/components/ui/icons/ResearchCoinIcon';
import Link from 'next/link';
import { AuthSharingService } from '@/services/auth-sharing.service';
import { signOutUser } from '@/utils/auth';
import { navigateToAuthorProfile } from '@/utils/navigation';
import { useVerification } from '@/contexts/VerificationContext';
import { YouPanel } from '@/components/You/YouPanel';
Expand Down Expand Up @@ -213,7 +213,7 @@ export default function UserMenu({
</Link>

<BaseMenuItem
onClick={() => AuthSharingService.signOutFromBothApps()}
onClick={() => signOutUser()}
className="w-full px-4 py-2"
data-testid="user-menu-signout"
>
Expand Down
79 changes: 39 additions & 40 deletions components/providers/ClientProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { UserProvider } from '@/contexts/UserContext';
import { OrganizationProvider } from '@/contexts/OrganizationContext';
import { OnchainProvider } from '@/contexts/OnchainContext';
import { NavigationProvider } from '@/contexts/NavigationContext';
import { AuthSharingWrapper } from '@/components/AuthSharingWrapper';
import { LegacyAuthCookieCleanup } from '@/components/LegacyAuthCookieCleanup';
import { VerificationProvider } from '@/contexts/VerificationContext';
import SignupModalContainer from '@/components/modals/SignupModalContainer';
import { ShareModalProvider } from '@/contexts/ShareContext';
Expand All @@ -34,49 +34,48 @@ export function ClientProviders({ children, session }: ClientProvidersProps) {
return (
<>
<ApmProvider />
<LegacyAuthCookieCleanup />
<NavigationProvider>
<OnchainProvider>
<NextAuthProvider session={session}>
<ReferralProvider>
<AuthSharingWrapper>
<AuthModalProvider>
<>
<UserProvider>
<PendingCountsProvider>
<VerificationProvider>
<ExchangeRateProvider>
<CurrencyPreferenceProvider>
{/* Above the layouts because the left sidebar
carries the funding power card and mounts
outside PageLayout on some routes. */}
<FundingPowerProvider>
<NotificationProvider>
<OrganizationProvider>
{/* Above the layouts: every page's left
sidebar lists these documents, and
navigating must not fetch them again. */}
<FundingNotesProvider>
<UserListsProvider>
<DismissedFeaturesProvider>
{/* Inside the user providers: the share
modal's post preview shows the sharer. */}
<ShareModalProvider>{children}</ShareModalProvider>
<FeatureNotifications />
</DismissedFeaturesProvider>
</UserListsProvider>
</FundingNotesProvider>
</OrganizationProvider>
</NotificationProvider>
</FundingPowerProvider>
</CurrencyPreferenceProvider>
</ExchangeRateProvider>
</VerificationProvider>
</PendingCountsProvider>
</UserProvider>
<SignupModalContainer />
</>
</AuthModalProvider>
</AuthSharingWrapper>
<AuthModalProvider>
<>
<UserProvider>
<PendingCountsProvider>
<VerificationProvider>
<ExchangeRateProvider>
<CurrencyPreferenceProvider>
{/* Above the layouts because the left sidebar
carries the funding power card and mounts
outside PageLayout on some routes. */}
<FundingPowerProvider>
<NotificationProvider>
<OrganizationProvider>
{/* Above the layouts: every page's left
sidebar lists these documents, and
navigating must not fetch them again. */}
<FundingNotesProvider>
<UserListsProvider>
<DismissedFeaturesProvider>
{/* Inside the user providers: the share
modal's post preview shows the sharer. */}
<ShareModalProvider>{children}</ShareModalProvider>
<FeatureNotifications />
</DismissedFeaturesProvider>
</UserListsProvider>
</FundingNotesProvider>
</OrganizationProvider>
</NotificationProvider>
</FundingPowerProvider>
</CurrencyPreferenceProvider>
</ExchangeRateProvider>
</VerificationProvider>
</PendingCountsProvider>
</UserProvider>
<SignupModalContainer />
</>
</AuthModalProvider>
</ReferralProvider>
</NextAuthProvider>
<ToasterProvider />
Expand Down
3 changes: 0 additions & 3 deletions config/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Authentication token key used in cookies - it matches the old app's token name (rh-web/config/constants.js)
export const AUTH_TOKEN = 'researchhub.auth.token';

// ResearchHub Foundation account user ID - bounties created by this account display a flat $150 USD amount
// Set via NEXT_PUBLIC_FOUNDATION_USER_ID environment variable
export const FOUNDATION_USER_ID = process.env.NEXT_PUBLIC_FOUNDATION_USER_ID
Expand Down
4 changes: 2 additions & 2 deletions contexts/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createContext, useContext, ReactNode, useState, useEffect } from 'react
import { useSession } from 'next-auth/react';
import { AuthError, AuthService } from '@/services/auth.service';
import type { User } from '@/types/user';
import { AuthSharingService } from '@/services/auth-sharing.service';
import { signOutUser } from '@/utils/auth';
import AnalyticsService from '@/services/analytics.service';

interface UserContextType {
Expand Down Expand Up @@ -41,7 +41,7 @@ export function UserProvider({ children }: { children: ReactNode }) {
} catch (err) {
if (err instanceof AuthError) {
if (err.code === 401) {
await AuthSharingService.signOutFromBothApps();
await signOutUser();
}
}
if (!silent) setError(err instanceof Error ? err : new Error('Failed to load user data'));
Expand Down
Loading