feat: refresh account info after managing cloud storage (#2648)

This commit is contained in:
Huang Xin
2025-12-08 20:13:20 +08:00
committed by GitHub
parent 6eb7d91122
commit 50cd7f80c6
5 changed files with 22 additions and 19 deletions
+1 -1
View File
@@ -69,7 +69,7 @@ jobs:
repo: context.repo.repo,
tag_name: process.env.release_tag,
})
const notes = process.env.release_note.split(/(?:\d\.\s)/).filter(Boolean);
const notes = process.env.release_note.split(/\d+\.\s/).filter(Boolean);
const formattedNotes = notes.map(note => `* ${note.trim()}`).join("\n");
const body = `## Release Highlight\n${formattedNotes}\n\n${data.body}`;
github.rest.repos.updateRelease({
@@ -38,7 +38,6 @@ export function PublicationView({
const _ = useTranslation();
const router = useRouter();
const [downloading, setDownloading] = useState(false);
const [downloaded, setDownloaded] = useState(false);
const [downloadedBook, setDownloadedBook] = useState<Book | null>(null);
const [progress, setProgress] = useState<number | null>(null);
@@ -79,7 +78,6 @@ export function PublicationView({
}
setDownloading(true);
setDownloaded(false);
setProgress(null);
try {
@@ -150,13 +148,13 @@ export function PublicationView({
<div className='flex flex-wrap gap-2'>
{acquisitionLinks.map(({ rel, links }) => (
<div key={rel} className='flex gap-1'>
{links.length === 1 ? (
{links.length === 1 || downloadedBook ? (
<button
onClick={() => handleActionButton(links[0]!.href, links[0]!.type)}
disabled={downloading}
className={clsx(
'btn btn-primary min-w-20 rounded-3xl',
downloaded && 'btn-success',
downloadedBook && 'btn-success',
)}
>
{downloadedBook ? _('Open & Read') : getAcquisitionLabel(rel)}
@@ -173,7 +171,7 @@ export function PublicationView({
tabIndex={0}
className={clsx(
`btn btn-primary min-w-20 rounded-3xl ${downloading ? 'btn-disabled' : ''}`,
downloaded && 'btn-success',
downloadedBook && 'btn-success',
)}
>
{downloadedBook ? _('Open') : getAcquisitionLabel(rel)}
+2 -1
View File
@@ -52,7 +52,7 @@ const ProfilePage = () => {
const _ = useTranslation();
const router = useRouter();
const { appService } = useEnv();
const { token, user } = useAuth();
const { token, user, refresh } = useAuth();
const { safeAreaInsets, isRoundedWindow } = useThemeStore();
const [loading, setLoading] = useState(false);
@@ -91,6 +91,7 @@ const ProfilePage = () => {
setShowEmbeddedCheckout(false);
} else if (showStorageManager) {
setShowStorageManager(false);
refresh();
} else {
navigateToLibrary(router);
}
@@ -2,13 +2,13 @@
import Stripe from 'stripe';
import { Suspense, useEffect, useState } from 'react';
import { useSearchParams, useRouter } from 'next/navigation';
import { useAuth } from '@/context/AuthContext';
import { useTranslation } from '@/hooks/useTranslation';
import { getAPIBaseUrl, getNodeAPIBaseUrl } from '@/services/environment';
import { getAccessToken } from '@/utils/access';
import { supabase } from '@/utils/supabase';
import { PlanType } from '@/types/quota';
import Spinner from '@/components/Spinner';
import { VerifiedIAP } from '@/libs/payment/iap/types';
import Spinner from '@/components/Spinner';
const STRIPE_CHECK_URL = `${getAPIBaseUrl()}/stripe/check`;
const APPLE_IAP_VERIFY_URL = `${getNodeAPIBaseUrl()}/apple/iap-verify`;
@@ -34,6 +34,7 @@ const SuccessPageWithSearchParams = () => {
const [retryCount, setRetryCount] = useState(0);
const searchParams = useSearchParams();
const router = useRouter();
const { refresh } = useAuth();
const payment = searchParams?.get('payment');
const platform = searchParams?.get('platform');
const sessionId = searchParams?.get('session_id');
@@ -86,9 +87,7 @@ const SuccessPageWithSearchParams = () => {
currency: session.currency || undefined,
});
try {
await supabase.auth.refreshSession();
} catch {}
refresh();
} catch (error) {
console.error('Failed to fetch session status:', error);
setSessionStatus((prev) => ({ ...prev, status: 'failed' }));
@@ -138,9 +137,7 @@ const SuccessPageWithSearchParams = () => {
planType: purchase.planType,
});
try {
await supabase.auth.refreshSession();
} catch {}
refresh();
} catch (error) {
console.error('Failed to verify IAP transaction:', error);
setSessionStatus((prev) => ({ ...prev, status: 'failed' }));
@@ -198,9 +195,7 @@ const SuccessPageWithSearchParams = () => {
currency: purchase.currency,
});
try {
await supabase.auth.refreshSession();
} catch {}
refresh();
} catch (error) {
console.error('Failed to verify Android IAP transaction:', error);
setSessionStatus((prev) => ({ ...prev, status: 'failed' }));
+10 -1
View File
@@ -10,6 +10,7 @@ interface AuthContextType {
user: User | null;
login: (token: string, user: User) => void;
logout: () => void;
refresh: () => void;
}
const AuthContext = createContext<AuthContextType | undefined>(undefined);
@@ -91,8 +92,16 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
}
};
const refresh = async () => {
try {
await supabase.auth.refreshSession();
} catch {}
};
return (
<AuthContext.Provider value={{ token, user, login, logout }}>{children}</AuthContext.Provider>
<AuthContext.Provider value={{ token, user, login, logout, refresh }}>
{children}
</AuthContext.Provider>
);
};