Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions src/beacon/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import NextAuth from 'next-auth';
import { authOptions } from '@/lib/auth';

const handler = (req: any, res: any) => {
return NextAuth(req, res, authOptions);
};
const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };
4 changes: 2 additions & 2 deletions src/beacon/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default function LoginPage() {
authService.clearAllAuthData()
// Clean up the URL
router.replace('/login')
} else if (status === 'authenticated') {
} else if (status === 'authenticated' && !isTransitioning) {
Comment thread
OlukaGibson marked this conversation as resolved.
// User is authenticated, let middleware or client redirect them
const isAirqoAdmin = session?.user?.organization === 'AirQo' &&
(session?.user?.privilege?.toLowerCase()?.includes('admin') ||
Expand All @@ -149,7 +149,7 @@ export default function LoginPage() {
router.push("/dashboard/devices")
}
}
}, [router, status, session])
}, [router, status, session, isTransitioning])

/**
* Validates email format
Expand Down
8 changes: 5 additions & 3 deletions src/beacon/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ const normalizeNextAuthUrl = () => {
const currentEnv = config.environment;
const rawUrl = process.env.NEXTAUTH_URL;

// Check if NEXTAUTH_URL is missing or incorrectly set to localhost in staging/production
// Check if NEXTAUTH_URL is missing, localhost, or incorrectly set to production on staging
const isLocalhostUrl = !rawUrl || rawUrl.includes('localhost') || rawUrl.includes('127.0.0.1');
const isProdUrlOnStaging = rawUrl === 'https://beacon.airqo.net' && currentEnv === 'staging';

if (currentEnv === 'staging') {
if (isLocalhostUrl) {
if (isLocalhostUrl || isProdUrlOnStaging) {
process.env.NEXTAUTH_URL = 'https://staging-beacon.airqo.net';
}
} else if (currentEnv === 'production') {
if (isLocalhostUrl) {
if (isLocalhostUrl || rawUrl === 'https://staging-beacon.airqo.net') {
Comment thread
OlukaGibson marked this conversation as resolved.
process.env.NEXTAUTH_URL = 'https://beacon.airqo.net';
Comment thread
OlukaGibson marked this conversation as resolved.
}
} else {
Expand Down Expand Up @@ -335,3 +336,4 @@ export const authOptions: NextAuthOptions = {

debug: false,
};

12 changes: 7 additions & 5 deletions src/beacon/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ const getEnvironment = () => {
if (nextAuthUrl.includes('stage') || nextAuthUrl.includes('staging') || nextAuthUrl.includes('beacon-stage')) {
return 'staging';
}

const serviceName = (process.env.SERVICE_NAME || '').toLowerCase();
const podHostName = (process.env.HOSTNAME || '').toLowerCase();
if (serviceName.includes('stage') || podHostName.includes('stage')) {
return 'staging';
}
Comment thread
OlukaGibson marked this conversation as resolved.

if (nextAuthUrl.includes('localhost') || nextAuthUrl.includes('127.0.0.1')) {
const serviceName = (process.env.SERVICE_NAME || '').toLowerCase();
const podHostName = (process.env.HOSTNAME || '').toLowerCase();
if (serviceName.includes('stage') || podHostName.includes('stage')) {
return 'staging';
}
return 'development';
}

Expand Down
Loading