세션 만료 체크
- 서버에 로그인한 다음 클라이언트 세션키 값의 만료일자를 체크하여 클라이언트에서 만료 여부를 체크하고자 한다.
- API 호출 전에 실행하여 만료 여부를 확인하고 오류처리하려는 의도이다.
백앤드 설정
Section titled “백앤드 설정”-
시션키 이름 설정
- 세션 키값으로 일반적으로 많이 사용하는 JSESSIONID 값을 사용한다.
-
로그인 응답에 만료시간을 포함하도록 설정한다. (서버의 도움이 없으면 만료시간 체크는 불가능하기 때문이다.)
로그인 응답 DTO @Schema(description ="로그인을 위한 응답 DTO")@Getter@Setter@ToString@NoArgsConstructor@AllArgsConstructor@Builderpublic static class CommonAuthLoginResponseDto {@Schema(description = "로그인 사용자 정보")private User user;@Schema(description = "세션 만료 시간(초)")private Integer sessionMaxInactiveInterval;} -
로그인 응답 DTO 샘플 데이터
- 3600 = 60(분) * 60(초) = 1시간
{"payload": {"user": {"userId": 1000,"email": "****@****.**","name": "admin","password": null,"langCd": "ko","userToken": null,"useYn": "Y"},"sessionMaxInactiveInterval": 3600},"successYn": "Y","messageCd": "SUCCESS"}
프런트앤드 설정
Section titled “프런트앤드 설정”- 로그인 정보를 관리하기 위한 커스텀 훅 생성
Terminal window touch useSession.tsuseSession.ts