|
@@ -1,38 +1,23 @@
|
|
|
import {
|
|
import {
|
|
|
- LogoutResult,
|
|
|
|
|
- ContextType
|
|
|
|
|
|
|
+ LogoutResult, ContextType
|
|
|
} from "./types";
|
|
} from "./types";
|
|
|
import {
|
|
import {
|
|
|
User
|
|
User
|
|
|
} from "../../../models/User";
|
|
} from "../../../models/User";
|
|
|
import redis from "../../../config/redis";
|
|
import redis from "../../../config/redis";
|
|
|
|
|
|
|
|
-export const logout = async (context?: ContextType): Promise<LogoutResult> => {
|
|
|
|
|
|
|
+export const logout = async (context: ContextType): Promise<LogoutResult> => {
|
|
|
try {
|
|
try {
|
|
|
- if (!context) {
|
|
|
|
|
- return {
|
|
|
|
|
- message: "unauthorized-missing-context",
|
|
|
|
|
- code: 401
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
const {
|
|
const {
|
|
|
userID,
|
|
userID,
|
|
|
token
|
|
token
|
|
|
} = context;
|
|
} = context;
|
|
|
|
|
|
|
|
- if (!userID || !token) {
|
|
|
|
|
- return {
|
|
|
|
|
- message: "unauthorized-missing-user-information",
|
|
|
|
|
- code: 401
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
await User.findByIdAndUpdate(userID, {
|
|
await User.findByIdAndUpdate(userID, {
|
|
|
refreshToken: null
|
|
refreshToken: null
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- await redis.del(`user:${userID}`);
|
|
|
|
|
|
|
+ await redis.del(`${userID}`);
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
message: "logout-successful",
|
|
message: "logout-successful",
|