1- import { IN_ELECTRON } from "@follow/shared/constants"
21import { env } from "@follow/shared/env.desktop"
32import { whoami } from "@follow/store/user/getters"
43import { userActions } from "@follow/store/user/store"
@@ -9,53 +8,17 @@ import PKG from "@pkg"
98import { NetworkStatus , setApiStatus } from "~/atoms/network"
109import { setLoginModalShow } from "~/atoms/user"
1110
12- import { ipcServices } from "./client"
13- import { getAuthSessionToken , getClientId , getSessionId } from "./client-session"
14-
15- const electronFetch = async ( input : string | URL | Request , options : RequestInit = { } ) => {
16- const authService = ipcServices ?. auth as
17- | ( NonNullable < typeof ipcServices > [ "auth" ] & {
18- request ?: ( payload : {
19- input : string
20- init ?: { method ?: string ; headers ?: Record < string , string > ; body ?: string }
21- } ) => Promise < { status : number ; headers : Record < string , string > ; body : string } >
22- } )
23- | undefined
24-
25- if ( ! authService ?. request ) {
26- return fetch ( input . toString ( ) , {
27- ...options ,
28- cache : "no-store" ,
29- } )
30- }
31-
32- const headers = new Headers ( options . headers )
33- const response = await authService . request ( {
34- input : input . toString ( ) ,
35- init : {
36- method : options . method ,
37- headers : Object . fromEntries ( headers . entries ( ) ) ,
38- body : typeof options . body === "string" ? options . body : undefined ,
39- } ,
40- } )
41-
42- return new Response ( response . body , {
43- status : response . status ,
44- headers : response . headers ,
45- } )
46- }
11+ import { getClientId , getSessionId } from "./client-session"
4712
4813export const followClient = new FollowClient ( {
4914 credentials : "include" ,
5015 timeout : 30000 ,
5116 baseURL : env . VITE_API_URL ,
5217 fetch : async ( input , options = { } ) =>
53- IN_ELECTRON
54- ? electronFetch ( input , options )
55- : fetch ( input . toString ( ) , {
56- ...options ,
57- cache : "no-store" ,
58- } ) ,
18+ fetch ( input . toString ( ) , {
19+ ...options ,
20+ cache : "no-store" ,
21+ } ) ,
5922} )
6023
6124export const followApi = followClient . api
@@ -65,11 +28,6 @@ followClient.addRequestInterceptor(async (ctx) => {
6528 header [ "X-Client-Id" ] = getClientId ( )
6629 header [ "X-Session-Id" ] = getSessionId ( )
6730
68- const authSessionToken = IN_ELECTRON ? getAuthSessionToken ( ) : null
69- if ( authSessionToken ) {
70- header . Cookie = `__Secure-better-auth.session_token=${ authSessionToken } ; better-auth.session_token=${ authSessionToken } `
71- }
72-
7331 const apiHeader = createDesktopAPIHeaders ( { version : PKG . version } )
7432
7533 options . headers = {
@@ -107,10 +65,6 @@ followClient.addResponseInterceptor(async ({ response }) => {
10765 return response
10866 }
10967
110- if ( IN_ELECTRON && getAuthSessionToken ( ) ) {
111- return response
112- }
113-
11468 // Or we can present LoginModal here.
11569 // router.navigate("/login")
11670 // If any response status is 401, we can set auth fail. Maybe some bug, but if navigate to login page, had same issues
0 commit comments