mirror of
https://github.com/tale/headplane.git
synced 2026-08-18 17:06:17 +00:00
fix: API_KEY is no longer required for login to work
This commit is contained in:
@@ -33,14 +33,6 @@ export async function loader() {
|
||||
throw new Error('The COOKIE_SECRET environment variable is required')
|
||||
}
|
||||
|
||||
if (!process.env.API_KEY) {
|
||||
throw new Error('The API_KEY environment variable is required')
|
||||
}
|
||||
|
||||
if (!process.env.HEADSCALE_CONTAINER) {
|
||||
throw new Error('The HEADSCALE_CONTAINER environment variable is required')
|
||||
}
|
||||
|
||||
// eslint-disable-next-line unicorn/no-null
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -233,6 +233,7 @@ async function getOidcConfig() {
|
||||
let issuer = process.env.OIDC_ISSUER
|
||||
let client = process.env.OIDC_CLIENT_ID
|
||||
let secret = process.env.OIDC_CLIENT_SECRET
|
||||
const rootKey = process.env.API_KEY
|
||||
|
||||
if (!issuer || !client || !secret) {
|
||||
const config = await getConfig()
|
||||
@@ -250,6 +251,10 @@ async function getOidcConfig() {
|
||||
return
|
||||
}
|
||||
|
||||
if (!rootKey) {
|
||||
throw new Error('Cannot use OIDC without the root API_KEY variable set')
|
||||
}
|
||||
|
||||
return { issuer, client, secret }
|
||||
}
|
||||
|
||||
|
||||
+11
-4
@@ -1,4 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable no-constant-condition */
|
||||
import { setTimeout } from 'node:timers/promises'
|
||||
@@ -6,7 +6,7 @@ import { setTimeout } from 'node:timers/promises'
|
||||
import { Client } from 'undici'
|
||||
|
||||
import { getContext } from './config'
|
||||
import { pull } from './headscale'
|
||||
import { HeadscaleError, pull } from './headscale'
|
||||
|
||||
export async function sighupHeadscale() {
|
||||
const context = await getContext()
|
||||
@@ -61,9 +61,16 @@ export async function restartHeadscale() {
|
||||
let attempts = 0
|
||||
while (true) {
|
||||
try {
|
||||
await pull('v1/apikey', process.env.API_KEY!)
|
||||
// Acceptable blank because API_KEY is not required
|
||||
await pull('v1/apikey', process.env.API_KEY ?? '')
|
||||
return
|
||||
} catch {
|
||||
} catch (error) {
|
||||
// This means the server is up but the API key is invalid
|
||||
// This can happen if the user only uses API_KEY via cookies
|
||||
if (error instanceof HeadscaleError && error.status === 401) {
|
||||
break
|
||||
}
|
||||
|
||||
if (attempts > 10) {
|
||||
throw new Error('Headscale did not restart in time')
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export class HeadscaleError extends Error {
|
||||
|
||||
export class FatalError extends Error {
|
||||
constructor() {
|
||||
super('The Headscale server is not accessible or the API_KEY is invalid.')
|
||||
super('The Headscale server is not accessible or the supplied API key is invalid')
|
||||
this.name = 'FatalError'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user