forked from Remitwise-Org/Remitwise-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreferences-helpers.ts
More file actions
27 lines (26 loc) · 933 Bytes
/
Copy pathpreferences-helpers.ts
File metadata and controls
27 lines (26 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { NextRequest, NextResponse } from 'next/server';
import { requireAuth } from '@/lib/session';
import { prisma } from '@/lib/prisma';
/** Hydrate the locale cookie from saved preferences on profile load. */
export async function setLocaleFromPreferences(request: NextRequest) {
try {
const { address } = await requireAuth();
const user = await prisma.user.findUnique({
where: { stellar_address: address },
include: { preferences: true },
});
if (user?.preferences?.language) {
const response = NextResponse.json({ hydrated: true });
response.cookies.set('remitwise_locale', user.preferences.language, {
path: '/',
maxAge: 365 * 24 * 60 * 60,
sameSite: 'lax',
httpOnly: false,
});
return response;
}
return NextResponse.json({ hydrated: false });
} catch {
return NextResponse.json({ hydrated: false }, { status: 500 });
}
}