Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { AdminForthPlugin, Filters, AdminUser } from "adminforth";
import { AdminForthPlugin, Filters, AdminUser, HttpExtra } from "adminforth";
import type { IAdminForth, AdminForthResource } from "adminforth";
import { IHttpServer } from "adminforth";
import { randomUUID } from 'crypto';
import type { OAuth2Adapter } from "adminforth";
import { AdminForthDataTypes } from "adminforth";
import type { HttpExtra } from './types.js';

interface OAuthPluginOptions {
emailField: string;
Expand Down Expand Up @@ -130,19 +129,21 @@ export default class OAuthPlugin extends AdminForthPlugin {
});
}

const adminUser = {
dbUser: user,
pk: user.id,
username,
};
const toReturn = { allowedLogin: true, error: '' };
await this.adminforth.restApi.processLoginCallbacks(adminUser, toReturn, response, extra);
const adminUser = {
dbUser: user,
pk: user.id,
username,
};
const toReturn = { allowedLogin: true, error: '' };

const rememberMeDays = this.options.authenticationExpireDuration ?? this.adminforth.config.auth.rememberMeDays;
await this.adminforth.restApi.processLoginCallbacks(adminUser, toReturn, response, { ...extra }, rememberMeDays);
if (toReturn.allowedLogin) {
this.adminforth.auth.setAuthCookie({
response,
username,
pk: user.id,
expireInDays: this.options.authenticationExpireDuration ? this.options.authenticationExpireDuration : this.adminforth.config.auth.rememberMeDays
expireInDays: rememberMeDays
});
}
return toReturn;
Expand Down