@kikiutils/nitro-session
Version:
Easy-to-use nitro session.
50 lines (47 loc) • 1.75 kB
JavaScript
import { getRequestIP } from 'h3';
import { CookieOrHeaderDataHandler } from './cookie-or-header.mjs';
import { UnstorageDataHandler } from './unstorage.mjs';
class DataHandler {
constructor(handler, maxAge, strictIpValidation) {
this.
this.
this.
}
return getRequestIP(event, { xForwardedFor: true }) || getRequestIP(event);
}
static async createInstance(options) {
let handler;
if (options.storage?.data?.driver === 'cookie/header') {
handler = new CookieOrHeaderDataHandler(options.storage.data.options);
}
else
handler = await UnstorageDataHandler.createInstance(options.storage?.data || { driver: 'memory' });
return new this(handler, options.maxAge ?? 86400, !!options.strictIpValidation);
}
async delete(token) {
await this.
}
async get(event, token) {
const data = await this.
if (data && data[0] + this.
if (this.
return;
return data[1];
}
}
async setAndGetToken(event, data) {
const toSetData = [
Date.now(),
data,
];
if (this.
toSetData.push(this.
return await this.
}
}
export { DataHandler };
//# sourceMappingURL=index.mjs.map