rewardwee_auth_access
Version:
auth verify access for all microservices
91 lines (57 loc) • 2 kB
text/typescript
//login
//logout
//reset password
import { RESPONSE_TYPE } from "../helpers/customTypes";
import {
Schema, model, Types, Model, ObjectId
} from 'mongoose';
import {
LoginRecord
} from "bamble_store_schemas"
import { ErrorDataType, LogError } from "../helpers/errorReporting";
class AuthLoginClass{
public isUserLoggedIn(user_id:ObjectId, token: string, UserLoginRecord: Model<LoginRecord> ): Promise<RESPONSE_TYPE>{
return new Promise((resolve,reject)=>{
UserLoginRecord.findOne( {user_id,token, status:"ACTIVE" } , null)
.then((records: any)=>{
if(records === null){
reject({
data:[],
message:"user is not currently logged in",
status:200,
statusCode:"LOGIN_FAILED"
})
return;
}
else{
resolve({
data:records,
message:"user is logged in",
status:200,
statusCode:"LOGIN_SUCCESSFUL"
})
return;
}
})
.catch((err: any)=>{
let error_log: ErrorDataType = {
msg:`Error updating password. Error: ${err.message}` ,
status: "STRONG",
time: new Date().toUTCString(),
stack:err.stack,
class: <string> <unknown>this
}
LogError(error_log)
reject({
data:[],
message:"unknown error",
status:500,
statusCode:"UNKNOWN_ERROR"
})
return;
}
)
})
}
}
export const AuthLogin = new AuthLoginClass();