File tree Expand file tree Collapse file tree 11 files changed +38
-14
lines changed
Expand file tree Collapse file tree 11 files changed +38
-14
lines changed Original file line number Diff line number Diff line change 33import { cookies } from "next/headers" ;
44
55export async function deleteAccount ( initialState : any , formData : FormData ) {
6+ const sessionCookieValue = cookies ( ) . get ( 'session' ) ?. value
7+
68 const res = await fetch ( 'http://localhost:8000/account' , {
79 method : 'DELETE' ,
810 cache : 'no-store' ,
911 headers : {
1012 'Accept' : 'application/json' ,
1113 'Content-Type' : 'application/json' ,
12- 'Authorization' : `Bearer ${ cookies ( ) . get ( 'session' ) ?. value } `
14+ 'Authorization' : `Bearer ${ sessionCookieValue } `
1315 } ,
1416 body : JSON . stringify ( {
1517 password : formData . get ( 'password' ) ?. toString ( )
Original file line number Diff line number Diff line change 33import { cookies } from "next/headers" ;
44
55export async function emailChangeVerification ( initialState : any , formData : FormData ) {
6+ const sessionToken = cookies ( ) . get ( 'session' ) ?. value
67 try {
78 const res = await fetch ( 'http://localhost:8000/account/email-verification' , {
89 method : 'POST' ,
910 cache : 'no-store' ,
1011 headers : {
1112 'Accept' : 'application/json' ,
1213 'Content-Type' : 'application/json' ,
13- 'Authorization' : `Bearer ${ cookies ( ) . get ( 'session' ) ?. value } `
14+ 'Authorization' : `Bearer ${ sessionToken } `
1415 } ,
1516 body : JSON . stringify ( {
1617 code : formData . get ( 'code' ) ?. toString ( ) ,
Original file line number Diff line number Diff line change @@ -4,14 +4,15 @@ import {redirect} from "next/navigation";
44import { cookies } from "next/headers" ;
55
66export async function emailVerification ( initialState : any , formData : FormData ) {
7+ const sessionToken = cookies ( ) . get ( 'session' ) ?. value
78 try {
89 const res = await fetch ( 'http://localhost:8000/account/email-verification' , {
910 method : 'POST' ,
1011 cache : 'no-store' ,
1112 headers : {
1213 'Accept' : 'application/json' ,
1314 'Content-Type' : 'application/json' ,
14- 'Authorization' : `Bearer ${ cookies ( ) . get ( 'session' ) ?. value } `
15+ 'Authorization' : `Bearer ${ sessionToken } `
1516 } ,
1617 body : JSON . stringify ( {
1718 code : formData . get ( 'code' ) ?. toString ( ) ,
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ import {RecommendHistoryElement} from "@/app/types/recommend-history-element";
55import { notFound } from "next/navigation" ;
66
77export async function getRecommendHistory ( cursorId ?: number ) : Promise < RecommendHistoryElement [ ] > {
8+ const sessionToken = cookies ( ) . get ( 'session' ) ?. value
9+
810 let url = 'http://localhost:8000/account/recommend-history'
911
1012 if ( cursorId !== undefined ) {
@@ -14,7 +16,7 @@ export async function getRecommendHistory(cursorId?: number): Promise<RecommendH
1416 const res = await fetch ( url , {
1517 cache : 'no-store' ,
1618 headers : {
17- 'Authorization' : `Bearer ${ cookies ( ) . get ( 'session' ) ?. value } `
19+ 'Authorization' : `Bearer ${ sessionToken } `
1820 }
1921 } )
2022
Original file line number Diff line number Diff line change @@ -14,8 +14,10 @@ export async function getSurveyResult(answer: Array<any>) {
1414 'Content-Type' : 'application/json' ,
1515 }
1616
17- if ( cookies ( ) . has ( 'session' ) )
18- headers . Authorization = `Bearer ${ cookies ( ) . get ( 'session' ) ?. value } ` ;
17+ if ( cookies ( ) . has ( 'session' ) ) {
18+ const sessionToken = cookies ( ) . get ( 'session' ) ?. value
19+ headers . Authorization = `Bearer ${ sessionToken } ` ;
20+ }
1921
2022 const res = await fetch ( 'http://localhost:8000/survey' , {
2123 method : 'POST' ,
Original file line number Diff line number Diff line change @@ -2,11 +2,15 @@ import {cookies} from "next/headers";
22import type { AccountInfo } from "@/app/types/account-info" ;
33
44export async function getUserInfo ( ) : Promise < AccountInfo | null | - 1 > {
5+ const sessionToken = cookies ( ) . get ( 'session' ) ?. value
6+
7+ const authorization = "Bearer " + sessionToken
8+
59 try {
610 const res = await fetch ( 'http://localhost:8000/account' , {
711 cache : 'no-store' ,
812 headers : {
9- authorization : `Bearer ${ cookies ( ) . get ( 'session' ) ?. value } `
13+ authorization : authorization
1014 }
1115 } )
1216
Original file line number Diff line number Diff line change 33import { cookies } from "next/headers" ;
44
55export async function isLoggedIn ( ) {
6- if ( cookies ( ) . has ( 'session' ) ) {
6+ const hasSession = cookies ( ) . has ( 'session' )
7+
8+ if ( hasSession ) {
9+ const sessionToken = cookies ( ) . get ( 'session' ) ?. value
10+
711 const res = await fetch ( 'http://localhost:8000/account' , {
812 cache : 'no-store' ,
913 headers : {
10- authorization : `Bearer ${ cookies ( ) . get ( 'session' ) ?. value } `
14+ authorization : `Bearer ${ sessionToken } `
1115 }
1216 } )
1317
Original file line number Diff line number Diff line change 33import { cookies } from "next/headers" ;
44
55export async function passwordChange ( prevState : any , formData : FormData ) {
6+ const sessionToken = cookies ( ) . get ( 'session' ) ?. value
7+
68 const res = await fetch ( 'http://localhost:8000/account/password' , {
79 method : 'PATCH' ,
810 cache : 'no-store' ,
911 headers : {
1012 'Accept' : 'application/json' ,
1113 'Content-Type' : 'application/json' ,
12- 'authorization' : `Bearer ${ cookies ( ) . get ( 'session' ) ?. value } `
14+ 'authorization' : `Bearer ${ sessionToken } `
1315 } ,
1416 body : JSON . stringify ( {
1517 password : formData . get ( 'password' ) ?. toString ( ) ,
Original file line number Diff line number Diff line change 33import { cookies } from "next/headers" ;
44
55export async function requestEmailChange ( password : string , newEmail : string ) :Promise < true | number > {
6+ const sessionToken = cookies ( ) . get ( 'session' ) ?. value
7+
68 const res = await fetch ( 'http://localhost:8000/account/email' , {
79 method : 'PATCH' ,
810 cache : 'no-store' ,
911 headers : {
1012 'Accept' : 'application/json' ,
1113 'Content-Type' : 'application/json' ,
12- 'Authorization' : `Bearer ${ cookies ( ) . get ( 'session' ) ?. value } `
14+ 'Authorization' : `Bearer ${ sessionToken } `
1315 } ,
1416 body : JSON . stringify ( {
1517 password : password ,
Original file line number Diff line number Diff line change 33import { cookies } from "next/headers" ;
44
55export async function verificationEmailResend ( ) {
6- const res = await fetch ( 'http://localhost:8000/account/verification-mail-resend' , {
6+ const sessionToken = cookies ( ) . get ( 'session' ) ?. value
7+
8+ await fetch ( 'http://localhost:8000/account/verification-mail-resend' , {
79 cache : 'no-store' ,
810 headers : {
9- 'Authorization' : `Bearer ${ cookies ( ) . get ( 'session' ) ?. value } `
11+ 'Authorization' : `Bearer ${ sessionToken } `
1012 }
1113 } )
1214}
You can’t perform that action at this time.
0 commit comments