Merge pull request #1260 from lowdefy/auth-config

Extra Auth config
This commit is contained in:
Gerrie van Wyk 2022-07-06 14:17:39 +02:00 committed by GitHub
commit 00b79eb19d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 5 deletions

View File

@ -15,9 +15,9 @@
*/
import { get } from '@lowdefy/helpers';
function addUserFieldsToToken(context, { account, authConfig, profile, token }) {
function addUserFieldsToToken(context, { account, authConfig, profile, token, user }) {
// const { debug } = context.logger;
const objects = { account, profile };
const objects = { account, profile, user };
// TODO: Add when debug is fixed.
// debug('Adding userFields to user. Available provider data is:');
// debug(objects);

View File

@ -71,8 +71,11 @@ function createJWTCallback(context, { authConfig, plugins }) {
updated_at,
...token,
};
}
if (profile || user) {
if (authConfig.userFields) {
addUserFieldsToToken(context, { authConfig, account, profile, token });
addUserFieldsToToken(context, { authConfig, account, profile, token, user });
}
}

View File

@ -52,6 +52,7 @@ function getNextAuthConfig(context, { authJson, plugins }) {
nextAuthConfig.session = authConfig.session;
nextAuthConfig.theme = authConfig.theme;
nextAuthConfig.cookies = authConfig?.advanced?.cookies;
initialized = true;
return nextAuthConfig;
}

View File

@ -72,6 +72,14 @@ export default {
type: 'App "auth" should be an object.',
},
properties: {
advanced: {
type: 'object',
properties: {
cookies: {
type: 'object',
},
},
},
callbacks: {
type: 'array',
items: {

View File

@ -42,14 +42,14 @@ 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({ authUrl, callbackUrl, providerId } = {}) {
function login({ authUrl, callbackUrl, providerId, ...rest } = {}) {
if (type.isNone(providerId) && auth.authConfig.providers.length === 1) {
providerId = auth.authConfig.providers[0].id;
}
auth.signIn(
providerId,
{ callbackUrl: getCallbackUrl({ lowdefy, callbackUrl }) },
{ ...rest, callbackUrl: getCallbackUrl({ lowdefy, callbackUrl }) },
authUrl?.urlQuery
);
}

View File

@ -20,7 +20,10 @@
```
- Add env vars `NEXTAUTH_URL` and `NEXTAUTH_SECRET`.
- Add new callback urls to auth0 `{{ protocol }}{{ host }}/api/auth/callback/{{ providerId }}`.
- convert login params (`callbackUrl`, `authUrl.urlQuery`)
- Convert types to plugins.
- Replace `onEnter` and `onEnterAsync` with `onMount` and `onMountAsync`.
- Convert old loading on blocks to new loading.
- Convert all request operators except `_user`, to use `_payload`.
- Convert `Message` action to `DisplayMessage`
- Static files are no longer at 'public/...', (our logged out page for example)