리액트 set cookie 넣기

김원호·2022년 8월 15일
0

로그인 하는 페이지에서

import Cookies from "universal-cookie";
const cookies = new Cookies();

export function setRefreshTokenToCookie(data) {
  let now = new Date();
  let after1m = new Date();
  after1m.setMinutes(now.getMinutes() + 10);
  cookies.set("authorization", data, { path: "/", expires: after1m });
}

slice페이지

import { setRefreshTokenToCookie } from "../../components/Login";

let token=null;
export const __postLogin = createAsyncThunk("todos/postTodos", async (payload, thunkAPI) => {
  try {
    console.log('__postLogin=>',payload);
    // const data = await axios.post("http://서버 아이피주소/api/member/login", payload);
    const data = await axios.post("http://서버 아이피주소/api/member/login", payload);
    console.log("로그인성공데이터1:",data);
    
    token = data.headers.authorization;
    setRefreshTokenToCookie(data.headers.authorization);

    // return thunkAPI.fulfillWithValue(data.data);
  } catch (error) {
    // return thunkAPI.rejectWithValue(error);
  }
});
profile
당신은사랑받기위해태어난사람

0개의 댓글