commit b04e0b0d1399719726a9fe75de8ac9d42f8421b4
parent 4515c7e90fe05973eedea96d12aafdb8182b34d0
Author: Yongbin Kim <iam@yongbin.kim>
Date: Mon, 30 Jan 2023 10:22:36 +0900
feat: logout 페이지 추가
Signed-off-by: Yongbin Kim <iam@yongbin.kim>
Diffstat:
1 file changed, 32 insertions(+), 0 deletions(-)
diff --git a/pages/users/logout.tsx b/pages/users/logout.tsx
@@ -0,0 +1,32 @@
+import { getAccessTokenCookieName, getRefreshTokenCookieName } from '@/lib/env'
+import { deleteSession } from '@/lib/security/session'
+import { authenticationFromCookies } from '@/lib/security/token'
+import { GetServerSideProps } from 'next'
+
+export const getServerSideProps: GetServerSideProps = async (context) => {
+ const token = await authenticationFromCookies(context.req.cookies)
+ if (token != null) {
+ if (token.tid != null) {
+ await deleteSession(token.tid)
+ }
+
+ context.res.setHeader('Set-Cookie', [
+ `${getAccessTokenCookieName()}=; Path=/; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT`,
+ `${getRefreshTokenCookieName()}=; Path=/; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT`,
+ ])
+ }
+
+ return {
+ redirect: {
+ destination: '/users/login',
+ permanent: false,
+ },
+ props: {},
+ }
+}
+
+export default function LoginPage () {
+ return (
+ <></>
+ )
+}