init
This commit is contained in:
@@ -20,14 +20,24 @@ async function clearEmailInvitations(email: string, teamId: string) {
|
||||
}
|
||||
|
||||
// Check whether the user still exists on the database
|
||||
export async function deserialize(id: string, done: IDeserializeCallback) {
|
||||
export async function deserialize(user: { id: string | null }, done: IDeserializeCallback) {
|
||||
try {
|
||||
if (!user || !user.id) {
|
||||
return done(null, null);
|
||||
}
|
||||
|
||||
const {id} = user;
|
||||
const excludedSubscriptionTypes = ["TRIAL", "PADDLE"];
|
||||
const q = `SELECT deserialize_user($1) AS user;`;
|
||||
const result = await db.query(q, [id]);
|
||||
if (result.rows.length) {
|
||||
const [data] = result.rows;
|
||||
if (data?.user) {
|
||||
const realExpiredDate = moment(data.user.valid_till_date).add(7, "days");
|
||||
data.user.is_expired = false;
|
||||
|
||||
data.user.is_member = !!data.user.team_member_id;
|
||||
if (excludedSubscriptionTypes.includes(data.user.subscription_type)) data.user.is_expired = realExpiredDate.isBefore(moment(), "days");
|
||||
|
||||
void setLastActive(data.user.id);
|
||||
void clearEmailInvitations(data.user.email, data.user.team_id);
|
||||
|
||||
Reference in New Issue
Block a user