File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
futuramaapi/routers/services/auth Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 88from futuramaapi .routers .services import BaseSessionService
99
1010
11+ class CookieAuthKeyIsNotDefinedError (Exception ): ...
12+
13+
1114class LogoutCookieSessionUserService (BaseSessionService [RedirectResponse ]):
1215 cookie_auth_key : ClassVar [str ] = "Authorization"
1316
@@ -23,11 +26,22 @@ def request(self) -> Request:
2326
2427 @property
2528 def _expire_session_statement (self ) -> Update :
26- key : str = self .request .cookies [self .cookie_auth_key ]
29+ try :
30+ key : str = self .request .cookies [self .cookie_auth_key ]
31+ except KeyError :
32+ raise CookieAuthKeyIsNotDefinedError () from None
33+
2734 return update (AuthSessionModel ).where (AuthSessionModel .key == key ).values (expired = True )
2835
2936 async def process (self , * args , ** kwargs ) -> RedirectResponse :
30- await self .session .execute (self ._expire_session_statement )
37+ try :
38+ await self .session .execute (self ._expire_session_statement )
39+ except CookieAuthKeyIsNotDefinedError :
40+ return RedirectResponse (
41+ "/auth" ,
42+ status_code = status .HTTP_302_FOUND ,
43+ )
44+
3145 await self .session .commit ()
3246
3347 response : RedirectResponse = RedirectResponse (
You can’t perform that action at this time.
0 commit comments