-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: backend bug and start auth flow with feide
- Loading branch information
1 parent
65986b7
commit 1570073
Showing
8 changed files
with
35 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
import { TRPCError } from '@trpc/server'; | ||
import { getTranslations } from 'next-intl/server'; | ||
import { cookies } from 'next/headers'; | ||
|
||
import { routing } from '@/lib/locale'; | ||
|
||
async function getLocaleFromCookie() { | ||
const cookieStore = await cookies(); | ||
const locale = cookieStore.get('locale')?.value ?? routing.defaultLocale; | ||
if (!routing.locales.includes(locale as 'en')) { | ||
const t = await getTranslations('error'); | ||
throw new TRPCError({ | ||
code: 'BAD_REQUEST', | ||
message: t('invalidLocale', { locale }), | ||
}); | ||
function getLocaleFromRequest(request: Request) { | ||
const acceptLanguage = request.headers.get('accept-language'); | ||
if (!acceptLanguage) { | ||
return routing.defaultLocale; | ||
} | ||
return locale; | ||
const preferredLocale = | ||
acceptLanguage.split(',').at(0)?.split(';').at(0)?.toLowerCase().trim() ?? | ||
''; | ||
|
||
return routing.locales.includes( | ||
preferredLocale as (typeof routing.locales)[number], | ||
) | ||
? (preferredLocale as (typeof routing.locales)[number]) | ||
: routing.defaultLocale; | ||
} | ||
|
||
export { getLocaleFromCookie }; | ||
export { getLocaleFromRequest }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters