forked from OpenWF/SpaceNinjaServer
Now when logging in and out of the game, the webui is notified so it can refresh the nonce, removing the need for constant login requests to revalidate it. Closes #2223 Reviewed-on: OpenWF/SpaceNinjaServer#2226 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
import { IDatabaseAccountJson, IIgnore } from "@/src/types/loginTypes";
|
|
import { model, Schema, SchemaOptions } from "mongoose";
|
|
|
|
const opts = {
|
|
toJSON: { virtuals: true },
|
|
toObject: { virtuals: true }
|
|
} satisfies SchemaOptions;
|
|
|
|
const databaseAccountSchema = new Schema<IDatabaseAccountJson>(
|
|
{
|
|
email: { type: String, required: true, unique: true },
|
|
password: { type: String, required: true },
|
|
DisplayName: { type: String, required: true, unique: true },
|
|
CountryCode: { type: String, default: "" },
|
|
ClientType: { type: String },
|
|
CrossPlatformAllowed: { type: Boolean, default: true },
|
|
ForceLogoutVersion: { type: Number, default: 0 },
|
|
AmazonAuthToken: { type: String },
|
|
AmazonRefreshToken: { type: String },
|
|
ConsentNeeded: { type: Boolean, default: false },
|
|
TrackedSettings: { type: [String], default: [] },
|
|
Nonce: { type: Number, default: 0 },
|
|
BuildLabel: String,
|
|
Dropped: Boolean,
|
|
LastLogin: { type: Date, default: 0 },
|
|
LatestEventMessageDate: { type: Date, default: 0 },
|
|
LastLoginRewardDate: { type: Number, default: 0 },
|
|
LoginDays: { type: Number, default: 1 }
|
|
},
|
|
opts
|
|
);
|
|
|
|
databaseAccountSchema.set("toJSON", {
|
|
transform(_document, returnedObject) {
|
|
delete returnedObject._id;
|
|
delete returnedObject.__v;
|
|
},
|
|
virtuals: true
|
|
});
|
|
|
|
export const Account = model<IDatabaseAccountJson>("Account", databaseAccountSchema);
|
|
|
|
const ignoreSchema = new Schema<IIgnore>({
|
|
ignorer: Schema.Types.ObjectId,
|
|
ignoree: Schema.Types.ObjectId
|
|
});
|
|
|
|
ignoreSchema.index({ ignorer: 1 });
|
|
ignoreSchema.index({ ignorer: 1, ignoree: 1 }, { unique: true });
|
|
|
|
export const Ignore = model<IIgnore>("Ignore", ignoreSchema);
|