- Introduced `oauthLogin` method in `electron/preload.ts` and backend IPC handlers for OAuth via `BrowserWindow`. - Replaced web-based OAuth redirection with Electron-specific implementation for Google, Facebook, and Apple. - Refactored `SocialForm.tsx` to handle OAuth login success and token management via Electron. - Updated `User`, `QuillSense`, and context methods to include `quill-trial` subscriptions and extended login logic. - Cleaned up code, removed unused imports, and improved error handling for authentication scenarios.
106 lines
3.0 KiB
TypeScript
106 lines
3.0 KiB
TypeScript
import {SelectBoxProps} from "@/shared/interface";
|
|
import {BookProps} from "@/lib/models/Book";
|
|
import {SessionProps} from "@/lib/models/Session";
|
|
|
|
export interface Author {
|
|
id: string;
|
|
name: string;
|
|
}
|
|
|
|
export interface UserProps {
|
|
id: string;
|
|
name: string;
|
|
lastName: string;
|
|
username: string;
|
|
authorName?: string;
|
|
email?: string;
|
|
accountVerified?: boolean;
|
|
termsAccepted?: boolean;
|
|
aiUsage: number,
|
|
apiKeys: {
|
|
gemini: boolean
|
|
openai: boolean,
|
|
anthropic: boolean,
|
|
},
|
|
guideTour?: GuideTour[];
|
|
subscription?: Subscription[];
|
|
writingLang: number;
|
|
writingLevel: number;
|
|
ritePoints: number;
|
|
creditsBalance:number;
|
|
groupId: number;
|
|
}
|
|
|
|
export interface GuideTour {
|
|
[key: string]: boolean;
|
|
}
|
|
|
|
export interface Subscription {
|
|
subType: string;
|
|
subTier: number;
|
|
status: boolean;
|
|
}
|
|
|
|
export const writingLevel: SelectBoxProps[] = [
|
|
{value: '0', label: 'Sélectionner un niveau d\'écriture'},
|
|
{value: '1', label: 'Je suis débutant'},
|
|
{value: '2', label: 'Je suis intermédiaire'},
|
|
{value: '3', label: 'Je suis avancé'},
|
|
];
|
|
|
|
export default class User {
|
|
static getCurrentSubscription(user: UserProps | null, type: "quill-sense" | "use-your-keys" | "quill-trial"): Subscription | null {
|
|
if (!user || !user.subscription || user.subscription.length === 0) {
|
|
return null;
|
|
}
|
|
return user.subscription.find((sub: Subscription): boolean => {
|
|
return sub.subType === type && sub.status;
|
|
}) || null;
|
|
}
|
|
static getWritingLevel(level: number): string {
|
|
switch (level) {
|
|
case 1:
|
|
return 'Débutant';
|
|
case 2:
|
|
return 'Intermédiaire';
|
|
case 3:
|
|
return 'Avancé';
|
|
default:
|
|
return 'Débutant';
|
|
}
|
|
}
|
|
|
|
static guideTourDone(guide: GuideTour[], tour: string): boolean {
|
|
if (!tour) return false;
|
|
|
|
// Vérifier d'abord dans le guide du serveur
|
|
if (guide && guide.find((guide: GuideTour): boolean => guide[tour]) !== undefined) {
|
|
return false;
|
|
}
|
|
|
|
// Vérifier ensuite dans localStorage pour le mode offline
|
|
if (typeof window !== 'undefined' && window.localStorage) {
|
|
const completedGuides = JSON.parse(localStorage.getItem('completedGuides') || '[]');
|
|
if (completedGuides.includes(tour)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static setNewGuideTour(session: SessionProps, tour: string): SessionProps {
|
|
const newGuideTour: { [key: string]: boolean }[] = [
|
|
...(session?.user?.guideTour ?? []),
|
|
{[tour]: true}
|
|
];
|
|
return {
|
|
...session,
|
|
user: {
|
|
...session?.user as UserProps,
|
|
guideTour: newGuideTour
|
|
}
|
|
}
|
|
}
|
|
}
|