Skip to content

Commit

Permalink
feat: Export AuthAdapter to make it available for extension with cu…
Browse files Browse the repository at this point in the history
…stom authentication adapters (parse-community#8443)
  • Loading branch information
dblythy authored Mar 3, 2023
1 parent 656bca6 commit 40c1961
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/Adapters/Auth/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import loadAdapter from '../AdapterLoader';
import Parse from 'parse/node';
import AuthAdapter from './AuthAdapter';

const apple = require('./apple');
const gcenter = require('./gcenter');
Expand Down Expand Up @@ -153,22 +154,30 @@ function loadAuthAdapter(provider, authOptions) {
return;
}

const adapter = Object.assign({}, defaultAdapter);
const adapter = defaultAdapter instanceof AuthAdapter ? defaultAdapter : Object.assign({}, defaultAdapter);
const keys = [
'validateAuthData',
'validateAppId',
'validateSetUp',
'validateLogin',
'validateUpdate',
'challenge',
'policy'
];
const defaultAuthAdapter = new AuthAdapter();
keys.forEach(key => {
const existing = adapter?.[key];
if (existing && typeof existing === 'function' && existing.toString() === defaultAuthAdapter[key].toString()) {
adapter[key] = null;
}
});
const appIds = providerOptions ? providerOptions.appIds : undefined;

// Try the configuration methods
if (providerOptions) {
const optionalAdapter = loadAdapter(providerOptions, undefined, providerOptions);
if (optionalAdapter) {
[
'validateAuthData',
'validateAppId',
'validateSetUp',
'validateLogin',
'validateUpdate',
'challenge',
'policy',
].forEach(key => {
keys.forEach(key => {
if (optionalAdapter[key]) {
adapter[key] = optionalAdapter[key];
}
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import RedisCacheAdapter from './Adapters/Cache/RedisCacheAdapter';
import LRUCacheAdapter from './Adapters/Cache/LRUCache.js';
import * as TestUtils from './TestUtils';
import * as SchemaMigrations from './SchemaMigrations/Migrations';
import AuthAdapter from './Adapters/Auth/AuthAdapter';

import { useExternal } from './deprecated';
import { getLogger } from './logger';
Expand Down Expand Up @@ -43,4 +44,5 @@ export {
ParseGraphQLServer,
_ParseServer as ParseServer,
SchemaMigrations,
AuthAdapter,
};

0 comments on commit 40c1961

Please sign in to comment.