fix: Fix next auth session provider base path

This commit is contained in:
Sam Tolmay 2023-04-03 17:10:54 +02:00
parent 6223783b84
commit 715cdf2cc4
No known key found for this signature in database
GPG Key ID: D004126FCD1A6DF0
4 changed files with 16 additions and 11 deletions

View File

@ -1,8 +1,3 @@
{
"recommendations": [
"arcanis.vscode-zipfs",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"samuelcolvin.jinjahtml"
]
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "samuelcolvin.jinjahtml"]
}

View File

@ -18,6 +18,8 @@
import React, { useEffect, useRef } from 'react';
import { SessionProvider, signIn, signOut, useSession } from 'next-auth/react';
import lowdefyConfig from '../../build/config.json';
function Session({ children }) {
const wasAuthenticated = useRef(false);
const { data: session, status } = useSession();
@ -40,9 +42,12 @@ function Session({ children }) {
function AuthConfigured({ authConfig, children, serverSession }) {
const auth = { signIn, signOut, authConfig };
let basePath = process.env.LOWDEFY_BASE_PATH ?? lowdefyConfig.basePath;
if (basePath) {
basePath = `${basePath}/api/auth`;
}
return (
<SessionProvider session={serverSession}>
<SessionProvider session={serverSession} basePath={basePath}>
<Session>
{(session) => {
auth.session = session;

View File

@ -18,6 +18,8 @@
import React, { useEffect, useRef } from 'react';
import { SessionProvider, signIn, signOut, useSession } from 'next-auth/react';
import lowdefyConfig from '../../build/config.json';
function Session({ children }) {
const wasAuthenticated = useRef(false);
const { data: session, status } = useSession();
@ -40,9 +42,12 @@ function Session({ children }) {
function AuthConfigured({ authConfig, children, serverSession }) {
const auth = { signIn, signOut, authConfig };
let basePath = process.env.LOWDEFY_BASE_PATH ?? lowdefyConfig.basePath;
if (basePath) {
basePath = `${basePath}/api/auth`;
}
return (
<SessionProvider session={serverSession}>
<SessionProvider session={serverSession} basePath={basePath}>
<Session>
{(session) => {
auth.session = session;

View File

@ -2,7 +2,7 @@ const withLess = require('next-with-less');
const lowdefyConfig = require('./build/config.json');
module.exports = withLess({
basePath: process.env.LOWDEFY_BASE_PATH || lowdefyConfig.basePath,
basePath: process.env.LOWDEFY_BASE_PATH ?? lowdefyConfig.basePath,
reactStrictMode: true,
webpack: (config, { isServer }) => {
if (!isServer) {