fix: Auth bug fixes.

This commit is contained in:
Sam 2022-05-12 17:47:53 +02:00
parent 557669e798
commit 3fe249c36e
No known key found for this signature in database
GPG Key ID: D004126FCD1A6DF0
4 changed files with 16 additions and 14 deletions

View File

@ -25,20 +25,17 @@ function createRedirectCallback({ authConfig, plugins }) {
if (redirectCallbackPlugins.length === 0) return undefined;
if (redirectCallbackPlugins.length !== 1) {
throw new Error('More than one auth redirect callbacks are configured. Only one is allowed.');
}
const [plugin] = redirectCallbackPlugins;
async function redirectCallback({ url, baseUrl }) {
let callbackUrl;
// TODO: Is there a point in running all the callbacks if only the last one is used?
// Else we can enforce only one.
for (const plugin of redirectCallbackPlugins) {
callbackUrl = await plugin.fn({
properties: plugin.properties ?? {},
baseUrl,
url,
});
}
return callbackUrl;
return plugin.fn({
properties: plugin.properties ?? {},
baseUrl,
url,
});
}
return redirectCallback;
}

View File

@ -39,6 +39,9 @@ async function validateAuthConfig({ components }) {
if (type.isNone(components.auth.providers)) {
components.auth.providers = [];
}
if (type.isNone(components.auth.theme)) {
components.auth.theme = {};
}
const { valid } = validate({
schema: lowdefySchema.definitions.authConfig,

View File

@ -37,7 +37,7 @@ function getCallbackUrl({ lowdefy, callbackUrl = {} }) {
function createAuthMethods(lowdefy, auth) {
// login and logout are Lowdefy function that handle action params
// signIn and signOut are the next-auth methods
function login({ providerId, callbackUrl, authUrl = {} }) {
function login({ providerId, callbackUrl, authUrl = {} } = {}) {
// TODO: if only one provider exists, pass provider here
// to link directly to provider
auth.signIn(

View File

@ -23,6 +23,7 @@ import setupWatcher from '../utils/setupWatcher.mjs';
const hashes = {};
const watchedFiles = [
'build/auth.json',
'build/config.json',
'build/plugins/actions.js',
'build/plugins/blocks.js',
@ -86,6 +87,7 @@ async function nextBuildWatcher(context) {
watchDotfiles: true,
watchPaths: [
path.join(context.directories.build, 'plugins'),
path.join(context.directories.build, 'auth.json'),
path.join(context.directories.build, 'config.json'),
path.join(context.directories.server, 'package.json'),
],