Skip to content

Commit c44fc0f

Browse files
committed
refactor: improve type safety and cookie handling in authentication - Updated cookie handling to use await for asynchronous operations - Enhanced type safety in user object properties in getServerUser function - Refactored stellar network conversion functions for clarity and consistency
1 parent 67fd56f commit c44fc0f

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

lib/auth/server-auth.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface ServerUser {
1818

1919
export async function getServerUser(): Promise<ServerUser | null> {
2020
try {
21-
const cookieStore = cookies();
21+
const cookieStore = await cookies();
2222
const accessToken = cookieStore.get('accessToken')?.value;
2323

2424
if (!accessToken) {
@@ -28,10 +28,10 @@ export async function getServerUser(): Promise<ServerUser | null> {
2828
const user = await getMe(accessToken);
2929

3030
return {
31-
id: user._id || user.id,
32-
email: user.email,
33-
name: user.profile?.firstName || user.name,
34-
image: user.profile?.avatar || user.image,
31+
id: (user._id || user.id) as string,
32+
email: user.email as string,
33+
name: (user.profile?.firstName || user.name) as string | null,
34+
image: (user.profile?.avatar || user.image) as string | null,
3535
role: user.roles?.[0] === 'ADMIN' ? 'ADMIN' : 'USER',
3636
isVerified: user.isVerified,
3737
profile: user.profile,
@@ -53,7 +53,7 @@ export async function requireServerAuth(): Promise<ServerUser> {
5353
}
5454

5555
export async function getServerAuthHeaders(): Promise<Record<string, string>> {
56-
const cookieStore = cookies();
56+
const cookieStore = await cookies();
5757
const accessToken = cookieStore.get('accessToken')?.value;
5858

5959
return accessToken ? { Authorization: `Bearer ${accessToken}` } : {};

lib/wallet-utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,19 +347,19 @@ export function parseNetwork(network: string): NetworkType | null {
347347
}
348348

349349
/**
350-
* Convert StellarNetwork enum to NetworkType
351-
* @param network - StellarNetwork enum value
350+
* Convert StellarNetwork type to NetworkType
351+
* @param network - StellarNetwork type value
352352
* @returns NetworkType
353353
*/
354354
export function stellarNetworkToType(network: StellarNetwork): NetworkType {
355-
return network === StellarNetwork.TESTNET ? 'testnet' : 'public';
355+
return network === 'testnet' ? 'testnet' : 'public';
356356
}
357357

358358
/**
359-
* Convert NetworkType to StellarNetwork enum
359+
* Convert NetworkType to StellarNetwork type
360360
* @param network - NetworkType
361-
* @returns StellarNetwork enum value
361+
* @returns StellarNetwork type value
362362
*/
363363
export function networkTypeToStellar(network: NetworkType): StellarNetwork {
364-
return network === 'testnet' ? StellarNetwork.TESTNET : StellarNetwork.PUBLIC;
364+
return network === 'testnet' ? 'testnet' : 'public';
365365
}

0 commit comments

Comments
 (0)