Skip to content

Commit 5924a03

Browse files
Revert "Next fix (#219)" (#220)
This reverts commit 3b2d0d5.
1 parent 3b2d0d5 commit 5924a03

23 files changed

+114
-134
lines changed

frontend/actions/auth.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { revalidatePath } from "next/cache";
44
import { createSupabaseClient } from "@/utils/supabase/server";
55
import { loginInitialState, requiredOnboardingProgress, signupInitialState } from "@/types/user";
66
import { createClient } from "@supabase/supabase-js";
7-
import { getCompanyServerSide } from "@/api/company-server";
8-
import { importQuickbooksDataServerSide } from "../api/quickbooks-server";
7+
import { importQuickbooksData } from "@/api/quickbooks";
8+
import { getCompany } from "@/api/company";
99

1010
export async function login(prevState: loginInitialState, formData: FormData) {
1111
const supabase = await createSupabaseClient();
@@ -21,9 +21,9 @@ export async function login(prevState: loginInitialState, formData: FormData) {
2121
};
2222
}
2323

24-
const company = await getCompanyServerSide();
24+
const company = await getCompany();
2525
if (company?.externals) {
26-
importQuickbooksDataServerSide();
26+
importQuickbooksData();
2727
}
2828

2929
revalidatePath("/", "layout");

frontend/api/business-profile.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
"use server";
12
import { DocumentResponse, PresignedUploadResponse, DocumentCategories, DocumentTypes } from "@/types/documents";
2-
import { authHeader, clientAuthWrapper, getClient } from "./client";
3+
import { authHeader, authWrapper, getClient } from "./client";
34
import { getCompany } from "./company";
45
import { gzip } from "pako";
56

@@ -27,7 +28,7 @@ export const getAllDocuments = async (): Promise<DocumentResponse[]> => {
2728
return data;
2829
};
2930

30-
return clientAuthWrapper<DocumentResponse[]>()(req);
31+
return authWrapper<DocumentResponse[]>()(req);
3132
};
3233

3334
export async function getBusinessDocumentUploadUrl(
@@ -55,7 +56,7 @@ export async function getBusinessDocumentUploadUrl(
5556
return data;
5657
};
5758

58-
return clientAuthWrapper<PresignedUploadResponse>()(req);
59+
return authWrapper<PresignedUploadResponse>()(req);
5960
}
6061

6162
export async function confirmBusinessDocumentUpload(
@@ -83,7 +84,7 @@ export async function confirmBusinessDocumentUpload(
8384
}
8485
};
8586

86-
return clientAuthWrapper<void>()(req);
87+
return authWrapper<void>()(req);
8788
}
8889

8990
export async function updateDocumentCategory(documentId: string, category: DocumentCategories): Promise<void> {
@@ -100,7 +101,7 @@ export async function updateDocumentCategory(documentId: string, category: Docum
100101
}
101102
};
102103

103-
return clientAuthWrapper<void>()(req);
104+
return authWrapper<void>()(req);
104105
}
105106

106107
export async function deleteBusinessDocument(key: string, documentId: string): Promise<void> {
@@ -117,7 +118,7 @@ export async function deleteBusinessDocument(key: string, documentId: string): P
117118
}
118119
};
119120

120-
return clientAuthWrapper<void>()(req);
121+
return authWrapper<void>()(req);
121122
}
122123

123124
export async function uploadToS3(uploadUrl: string, file: File): Promise<void> {

frontend/api/claim-location.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { authHeader, clientAuthWrapper, getClient } from "./client";
1+
"use server";
2+
3+
import { authHeader, authWrapper, getClient } from "./client";
24
import { CreateClaimLocationRequest, CreateClaimLocationResponse } from "@/types/claim-location";
35

46
export const createClaimLocationLink = async (
@@ -16,5 +18,5 @@ export const createClaimLocationLink = async (
1618
throw Error(error?.error);
1719
}
1820
};
19-
return clientAuthWrapper<CreateClaimLocationResponse>()(req);
21+
return authWrapper<CreateClaimLocationResponse>()(req);
2022
};

frontend/api/claim.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use server";
12
import {
23
ConfirmDocumentUploadRequest,
34
ConfirmDocumentUploadResponse,
@@ -16,7 +17,7 @@ import {
1617
UploadClaimRelatedDocumentsRequest,
1718
UploadClaimRelatedDocumentsResponse,
1819
} from "@/types/claim";
19-
import { authHeader, clientAuthWrapper, getClient } from "./client";
20+
import { authHeader, authWrapper, getClient } from "./client";
2021

2122
export const createClaim = async (payload: CreateClaimRequest): Promise<CreateClaimResponse> => {
2223
const req = async (token: string): Promise<CreateClaimResponse> => {
@@ -31,7 +32,7 @@ export const createClaim = async (payload: CreateClaimRequest): Promise<CreateCl
3132
throw Error(error?.error);
3233
}
3334
};
34-
return clientAuthWrapper<CreateClaimResponse>()(req);
35+
return authWrapper<CreateClaimResponse>()(req);
3536
};
3637

3738
export const getClaims = async (input: GetCompanyClaimRequest): Promise<GetCompanyClaimResponse> => {
@@ -47,7 +48,7 @@ export const getClaims = async (input: GetCompanyClaimRequest): Promise<GetCompa
4748
throw Error(error?.error);
4849
}
4950
};
50-
return clientAuthWrapper<GetCompanyClaimResponse>()(req);
51+
return authWrapper<GetCompanyClaimResponse>()(req);
5152
};
5253

5354
export const getPurchaseLineItemsFromClaim = async (params: {
@@ -71,7 +72,7 @@ export const getPurchaseLineItemsFromClaim = async (params: {
7172
throw Error(error?.error);
7273
}
7374
};
74-
return clientAuthWrapper<GetClaimLineItemsResponse>()(req);
75+
return authWrapper<GetClaimLineItemsResponse>()(req);
7576
};
7677

7778
export const getClaimById = async (claimId: string): Promise<GetClaimByIdResponse> => {
@@ -89,7 +90,7 @@ export const getClaimById = async (claimId: string): Promise<GetClaimByIdRespons
8990
throw Error(error?.error);
9091
}
9192
};
92-
return clientAuthWrapper<GetClaimByIdResponse>()(req);
93+
return authWrapper<GetClaimByIdResponse>()(req);
9394
};
9495

9596
export const updateClaimStatus = async (
@@ -111,7 +112,7 @@ export const updateClaimStatus = async (
111112
throw Error(error?.error);
112113
}
113114
};
114-
return clientAuthWrapper<UpdateClaimStatusResponse>()(req);
115+
return authWrapper<UpdateClaimStatusResponse>()(req);
115116
};
116117

117118
export const uploadAndConfirmDocumentRelation = async (
@@ -157,7 +158,7 @@ export const uploadClaimRelatedDocuments = async (
157158
throw Error(error?.error);
158159
}
159160
};
160-
return clientAuthWrapper<UploadClaimRelatedDocumentsResponse>()(req);
161+
return authWrapper<UploadClaimRelatedDocumentsResponse>()(req);
161162
};
162163

163164
export const conformUploadedDocument = async (
@@ -176,7 +177,7 @@ export const conformUploadedDocument = async (
176177
throw Error(error?.error);
177178
}
178179
};
179-
return clientAuthWrapper<ConfirmDocumentUploadResponse>()(req);
180+
return authWrapper<ConfirmDocumentUploadResponse>()(req);
180181
};
181182

182183
export const linkLineItemToClaim = async (claimId: string, purchaseLineItemId: string) => {
@@ -192,7 +193,7 @@ export const linkLineItemToClaim = async (claimId: string, purchaseLineItemId: s
192193
throw Error(error?.error);
193194
}
194195
};
195-
return clientAuthWrapper<LinkLineItemToClaimResponse>()(req);
196+
return authWrapper<LinkLineItemToClaimResponse>()(req);
196197
};
197198

198199
export const linkPurchaseToClaim = async (claimId: string, purchaseId: string) => {
@@ -208,7 +209,7 @@ export const linkPurchaseToClaim = async (claimId: string, purchaseId: string) =
208209
throw Error(error?.error);
209210
}
210211
};
211-
return clientAuthWrapper<LinkPurchaseToClaimResponse>()(req);
212+
return authWrapper<LinkPurchaseToClaimResponse>()(req);
212213
};
213214

214215
export const createClaimPDF = async (claimId: string) => {
@@ -226,7 +227,7 @@ export const createClaimPDF = async (claimId: string) => {
226227
throw Error(error?.error);
227228
}
228229
};
229-
return clientAuthWrapper<CreateClaimPDFResponse>()(req);
230+
return authWrapper<CreateClaimPDFResponse>()(req);
230231
};
231232

232233
export const deleteClaim = async (claimId: string) => {
@@ -244,5 +245,5 @@ export const deleteClaim = async (claimId: string) => {
244245
throw Error(error?.error);
245246
}
246247
};
247-
return clientAuthWrapper<DeleteClaimResponse>()(req);
248+
return authWrapper<DeleteClaimResponse>()(req);
248249
};

frontend/api/client.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,3 @@ export const authWrapper =
3737
export const getClientAuthToken = async (): Promise<string> => {
3838
return await getAuthToken();
3939
};
40-
41-
/**
42-
* Client-side: Wraps a function that needs authentication token
43-
* Uses getAuthToken() which reads from browser cookies/storage
44-
*/
45-
export const clientAuthWrapper =
46-
<T>() =>
47-
async (fn: (token: string) => Promise<T>) => {
48-
const token = await getAuthToken();
49-
return fn(token);
50-
};

frontend/api/company-server.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

frontend/api/company.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use server";
12
import {
23
Company,
34
CompanyHasDataResponse,
@@ -7,7 +8,7 @@ import {
78
UpdateCompanyRequest,
89
UpdateCompanyResponse,
910
} from "@/types/company";
10-
import { authHeader, clientAuthWrapper, getClient } from "./client";
11+
import { authHeader, authWrapper, getClient } from "./client";
1112

1213
export const createCompany = async (payload: CreateCompanyRequest): Promise<Company> => {
1314
const req = async (token: string): Promise<Company> => {
@@ -22,7 +23,7 @@ export const createCompany = async (payload: CreateCompanyRequest): Promise<Comp
2223
throw Error(error?.error);
2324
}
2425
};
25-
return clientAuthWrapper<Company>()(req);
26+
return authWrapper<Company>()(req);
2627
};
2728

2829
export const getCompanyLocations = async (): Promise<GetCompanyLocationsResponse> => {
@@ -37,7 +38,7 @@ export const getCompanyLocations = async (): Promise<GetCompanyLocationsResponse
3738
throw Error(error?.error);
3839
}
3940
};
40-
return clientAuthWrapper<GetCompanyLocationsResponse>()(req);
41+
return authWrapper<GetCompanyLocationsResponse>()(req);
4142
};
4243

4344
export const getCompany = async (): Promise<Company> => {
@@ -52,7 +53,7 @@ export const getCompany = async (): Promise<Company> => {
5253
throw Error(error?.error);
5354
}
5455
};
55-
return clientAuthWrapper<Company>()(req);
56+
return authWrapper<Company>()(req);
5657
};
5758

5859
export const getClaimInProgress = async (): Promise<GetClaimInProgressForCompanyResponse> => {
@@ -67,7 +68,7 @@ export const getClaimInProgress = async (): Promise<GetClaimInProgressForCompany
6768
throw Error(error?.error);
6869
}
6970
};
70-
return clientAuthWrapper<GetClaimInProgressForCompanyResponse>()(req);
71+
return authWrapper<GetClaimInProgressForCompanyResponse>()(req);
7172
};
7273

7374
export const companyHasData = async (): Promise<CompanyHasDataResponse> => {
@@ -82,7 +83,7 @@ export const companyHasData = async (): Promise<CompanyHasDataResponse> => {
8283
throw Error(error?.error);
8384
}
8485
};
85-
return clientAuthWrapper<CompanyHasDataResponse>()(req);
86+
return authWrapper<CompanyHasDataResponse>()(req);
8687
};
8788

8889
export const updateCompany = async (payload: UpdateCompanyRequest): Promise<UpdateCompanyResponse> => {
@@ -98,5 +99,5 @@ export const updateCompany = async (payload: UpdateCompanyRequest): Promise<Upda
9899
throw Error(error?.error);
99100
}
100101
};
101-
return clientAuthWrapper<UpdateCompanyResponse>()(req);
102+
return authWrapper<UpdateCompanyResponse>()(req);
102103
};

frontend/api/dashboard.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use server";
12
import { BannerData } from "@/types/user";
23
import { getNotifications } from "./notifications";
34
import { getClaimInProgress } from "./company";

frontend/api/fema-risk-index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
"use server";
2+
13
import { FemaRisKIndexCountiesFemaDisaster } from "@/types/fema-risk-index";
2-
import { authHeader, clientAuthWrapper, getClient } from "./client";
4+
import { authHeader, authWrapper, getClient } from "./client";
35

46
export const getFemaRiskIndexData = async (): Promise<FemaRisKIndexCountiesFemaDisaster> => {
57
const req = async (token: string): Promise<FemaRisKIndexCountiesFemaDisaster> => {
@@ -13,7 +15,7 @@ export const getFemaRiskIndexData = async (): Promise<FemaRisKIndexCountiesFemaD
1315
throw Error(error?.error);
1416
}
1517
};
16-
return clientAuthWrapper<FemaRisKIndexCountiesFemaDisaster>()(req);
18+
return authWrapper<FemaRisKIndexCountiesFemaDisaster>()(req);
1719
};
1820

1921
export const refreshFemaRiskIndexData = async (): Promise<void> => {
@@ -26,5 +28,5 @@ export const refreshFemaRiskIndexData = async (): Promise<void> => {
2628
throw Error(error?.error);
2729
}
2830
};
29-
return clientAuthWrapper<void>()(req);
31+
return authWrapper<void>()(req);
3032
};

frontend/api/insurance.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use server";
12
import {
23
CreateInsurancePolicyBulkRequest,
34
CreateInsurancePolicyRequest,
@@ -8,7 +9,7 @@ import {
89
UpdateInsurancePolicyRequest,
910
UpdateInsurancePolicyResponse,
1011
} from "@/types/insurance-policy";
11-
import { getClient, authHeader, clientAuthWrapper } from "./client";
12+
import { getClient, authHeader, authWrapper } from "./client";
1213

1314
export const createInsurancePolicy = async (payload: CreateInsurancePolicyRequest): Promise<InsurancePolicy> => {
1415
const req = async (token: string): Promise<InsurancePolicy> => {
@@ -23,7 +24,7 @@ export const createInsurancePolicy = async (payload: CreateInsurancePolicyReques
2324
throw Error(error?.error);
2425
}
2526
};
26-
return clientAuthWrapper<InsurancePolicy>()(req);
27+
return authWrapper<InsurancePolicy>()(req);
2728
};
2829

2930
export const createInsurancePolicyBulk = async (
@@ -41,7 +42,7 @@ export const createInsurancePolicyBulk = async (
4142
throw Error(error?.error);
4243
}
4344
};
44-
return clientAuthWrapper<InsurancePolicy[]>()(req);
45+
return authWrapper<InsurancePolicy[]>()(req);
4546
};
4647

4748
export const getInsurancePolicies = async (): Promise<GetInsurancePoliciesResponseType> => {
@@ -56,7 +57,7 @@ export const getInsurancePolicies = async (): Promise<GetInsurancePoliciesRespon
5657
throw Error(error?.error);
5758
}
5859
};
59-
return clientAuthWrapper<GetInsurancePoliciesResponseType>()(req);
60+
return authWrapper<GetInsurancePoliciesResponseType>()(req);
6061
};
6162

6263
export const updateInsurancePolicy = async (
@@ -74,7 +75,7 @@ export const updateInsurancePolicy = async (
7475
throw Error(error?.error);
7576
}
7677
};
77-
return clientAuthWrapper<UpdateInsurancePolicyResponse>()(req);
78+
return authWrapper<UpdateInsurancePolicyResponse>()(req);
7879
};
7980

8081
export const updateInsurancePolicyBulk = async (
@@ -92,7 +93,7 @@ export const updateInsurancePolicyBulk = async (
9293
throw Error(error?.error);
9394
}
9495
};
95-
return clientAuthWrapper<UpdateInsurancePolicyBulkResponse>()(req);
96+
return authWrapper<UpdateInsurancePolicyBulkResponse>()(req);
9697
};
9798

9899
export const deleteInsurancePolicy = async (insurancePolicyId: string): Promise<void> => {
@@ -110,5 +111,5 @@ export const deleteInsurancePolicy = async (insurancePolicyId: string): Promise<
110111
throw Error(error?.error);
111112
}
112113
};
113-
return clientAuthWrapper<void>()(req);
114+
return authWrapper<void>()(req);
114115
};

0 commit comments

Comments
 (0)