File tree Expand file tree Collapse file tree 2 files changed +17
-19
lines changed Expand file tree Collapse file tree 2 files changed +17
-19
lines changed Original file line number Diff line number Diff line change @@ -11,8 +11,7 @@ import WindowWrapper from '../components/Window/WindowWrapper';
11
11
import Providers from '../providers/Providers' ;
12
12
import { toUITheme } from '../utils/theme' ;
13
13
import { Modals } from '../components/Modals/Modals' ;
14
- import { getSSRApiRequestService } from '../factories/apiRequestService' ;
15
- import { DTOAccount } from 'podverse-helpers' ;
14
+ import { getSSRLoggedInAccount } from '../utils/auth/getSSRLoggedInAccount' ;
16
15
17
16
export const metadata = {
18
17
title : 'Podverse' ,
@@ -23,23 +22,7 @@ export default async function RootLayout({ children }: { children: React.ReactNo
23
22
const [ locale , cookieStore ] = await Promise . all ( [ getLocale ( ) , cookies ( ) ] ) ;
24
23
const cookieTheme = cookieStore . get ( 'theme' ) ?. value ;
25
24
const theme = toUITheme ( cookieTheme ) ;
26
-
27
- let jwt ;
28
- if ( typeof window === "undefined" ) {
29
- const cookieStore = await cookies ( ) ;
30
- jwt = cookieStore . get ( "jwt" ) ?. value ;
31
- }
32
- const ssrApiRequestService = getSSRApiRequestService ( jwt ) ;
33
-
34
- const hello = await ssrApiRequestService . reqAccountGetManyPublic ( ) ;
35
- console . log ( hello ) ;
36
-
37
- let ssrLoggedInAccount : DTOAccount | null = null ;
38
- try {
39
- ssrLoggedInAccount = await ssrApiRequestService . reqAuthMe ( ) ;
40
- } catch ( error ) {
41
- // do nothing
42
- }
25
+ const ssrLoggedInAccount = await getSSRLoggedInAccount ( ) ;
43
26
44
27
return (
45
28
< html lang = { locale } data-theme = { theme } >
Original file line number Diff line number Diff line change
1
+ import { cookies } from 'next/headers' ;
2
+ import { getSSRApiRequestService } from '../../factories/apiRequestService' ;
3
+ import { DTOAccount } from 'podverse-helpers' ;
4
+
5
+ export async function getSSRLoggedInAccount ( ) : Promise < DTOAccount | null > {
6
+ const cookieStore = await cookies ( ) ;
7
+ const jwt = cookieStore . get ( "jwt" ) ?. value ;
8
+ const ssrApiRequestService = getSSRApiRequestService ( jwt ) ;
9
+
10
+ try {
11
+ return await ssrApiRequestService . reqAuthMe ( ) ;
12
+ } catch {
13
+ return null ;
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments