-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
로그아웃 요청이 403 forbidden 에러가 나는데 왜그런걸까요??
24.06.22 21:26 작성 조회수 68
0
"success": false,
"code": 403,
"data": "Forbidden resource"
이렇게 에러가납니다.
@ApiCookieAuth('connect.sid')
@UseGuards(LoggedInGuard)
@Post('logout')
async logout(@Res() res) {
console.log(res);
res.clearCookie('connect.sid', { httpOnly: true });
return res.send('ok');
}
프론트에서는
const logoutMutation = useMutation({
mutationFn: () => {
return api.post("/api/teachers/logout");
},
onSuccess: (res) => {
localStorage.removeItem("teacherState");
router.push("/auth/login");
},
onError: (error) => {
console.log(error);
},
});
이런식으로 보내고있거든요 api는 axios에 credentials: true 와함꼐 보내고있습니다.
답변을 작성해보세요.
0
![조현영님의 프로필](https://cdn.inflearn.com/wp-content/uploads/avatars/14793/5bbebf0cc0f37-bpfull.png?w=48)
조현영
지식공유자2024.06.23
저건 지금 로그인을 안 한 상태에서 로그아웃 요청을 했다는 뜻입니다. api가 axios instance인 건가요? 일단 withCredentials와 상관 없이 로그인 후 쿠키가 브라우저에 심어졌는지 궁금하네요. 로그아웃 말고도 다른 api 요청도 403 뜨지 않나요?
![윤희중님의 프로필](https://cdn.inflearn.com/public/main/profile/default_profile.png?w=48)
윤희중
질문자2024.06.23
넵 쿠키가 브라우저에 심어졌습니다.
api는 axios 인스턴스가맞습니다.
// lib/api.ts
import axios from "axios";
const api = axios.create({
baseURL: "http://localhost:3095",
headers: {
"Content-Type": "application/json",
},
withCredentials: true,
});
export default api;
그리고 보면 브라우저에 쿠키가심어집니다. 그리고 처음에 로그인후 가입하면 정상적으로 로그인 /로그아웃이 되는걸 확인했는데요. 일정시간이지나면 로그아웃이안되는데 왜그런지 잘모르겠네요...
세션설정은 아래와같이 설정했습니다.
app.use(cookieParser());
app.use(
session({
resave: false,
saveUninitialized: false,
secret: process.env.COOKIE_SECRET,
cookie: {
httpOnly: true,
// maxAge : 6000 //
},
}),
);
확인해보면 nestjs를 끄지않고 나두면 아래에러가발생합니다. 그래서 다시 서버를 재시작하면 로그인 로그아웃이 정상적으로 되는걸확인했습니다. 그러나 일정시간이 지나면 다시 저에러가 나타나더라구요. 왜그런지 잘모르겠네요
[Nest] 18712 - 2024. 06. 23. 오후 3:14:56 ERROR [ExceptionsHandler] Connection is not established with mysql database
TypeORMError: Connection is not established with mysql database 이런에러가뜨네요 로그아웃하려고할때마다
![조현영님의 프로필](https://cdn.inflearn.com/wp-content/uploads/avatars/14793/5bbebf0cc0f37-bpfull.png?w=48)
조현영
지식공유자2024.06.23
Connection is not established with mysql database
에러메시지를 보면 지금 무언가때문에 DB와의 연결이 끊기는 것 같은데요. 그게 원인이 아닐까 싶습니다.
답변 1