Fixed auth
This commit is contained in:
@@ -1,11 +1,21 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
import { client } from "@/core/auth/oauth";
|
import { client } from "@/core/auth/oauth";
|
||||||
|
import { headers } from "next/headers";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
export default async function redirectAuth() {
|
export default async function redirectAuth() {
|
||||||
|
// Get headers of the incoming request
|
||||||
|
const hdrs = await headers();
|
||||||
|
|
||||||
|
// Get protocol and host
|
||||||
|
const host = hdrs.get("host");
|
||||||
|
const proto = hdrs.get("x-forwarded-proto") || "http";
|
||||||
|
|
||||||
|
const baseUrl = `${proto}://${host}`;
|
||||||
|
|
||||||
const authorizationUri = client.authorizeURL({
|
const authorizationUri = client.authorizeURL({
|
||||||
redirect_uri: "http://localhost:3000/api/auth/callback",
|
redirect_uri: `${baseUrl}/api/auth/callback`,
|
||||||
scope: "user:email",
|
scope: "user:email",
|
||||||
state: "random_state_string",
|
state: "random_state_string",
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user