feat(auth): Add authorize page

This commit is contained in:
Björn Benouarets
2026-01-21 06:40:53 +01:00
parent 74232ad2d2
commit 9e7841ee35
8 changed files with 90 additions and 38 deletions

View File

@@ -0,0 +1,33 @@
"use server";
export interface AuthorizeParams {
client_id: string;
redirect_uri: string;
response_type: string;
scope: string;
state: string;
}
export interface AuthorizeResponse {
success: boolean;
message: string;
code?: string;
state?: string;
}
export const authorize = async (params: AuthorizeParams, token: string): Promise<AuthorizeResponse> => {
if (!process.env.SECNEX_OAUTH2_API_HOST) {
return { success: false, message: "SecNex OAuth2 API host is not set" };
}
const response = await fetch(`${process.env.SECNEX_OAUTH2_API_HOST}/authorize`, {
method: "POST",
body: JSON.stringify(params),
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`,
},
});
const data = await response.json();
return { success: true, message: data.message, code: data.code, state: data.state };
};

View File

@@ -3,18 +3,18 @@
import { cookies } from "next/headers";
export const login = async (username: string, password: string): Promise<{ success: boolean, message: string, token?: string }> => {
if (!process.env.SECNEX_API_HOST || !process.env.SECNEX_API_KEY) {
if (!process.env.SECNEX_AUTH_API_HOST || !process.env.SECNEX_AUTH_API_KEY) {
return { success: false, message: "SecNex API host or key is not set" };
}
const cookieStore = await cookies();
try {
const response = await fetch(`${process.env.SECNEX_API_HOST}/login`, {
const response = await fetch(`${process.env.SECNEX_AUTH_API_HOST}/login`, {
method: "POST",
body: JSON.stringify({ username, password }),
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${process.env.SECNEX_API_KEY}`,
"Authorization": `Bearer ${process.env.SECNEX_AUTH_API_KEY}`,
},
});
const dataResponse = await response.json();