feat: create auth provider context

This commit is contained in:
2026-01-20 11:27:09 +07:00
parent e27b18b22e
commit eae3b2b3fc
10 changed files with 99 additions and 18 deletions

View File

@ -1,11 +1,11 @@
"use server";
import { backendFetch, BackendResponse } from "@/shared/helper/backendFetch";
import { backendFetch, BackendResponse } from "@/shared/helpers/backendFetch";
import { cookies } from "next/headers";
export const submitProviderCallback = async (
providerName: string,
queries?: unknown
queries?: unknown,
): Promise<
BackendResponse<{
authToken: string;
@ -15,7 +15,7 @@ export const submitProviderCallback = async (
const envKey = providerName.toUpperCase() + "_CALLBACK_URL";
const authClientCallbackUrl = (await backendFetch(
"auth/providers/" + providerName + "/callback"
"auth/providers/" + providerName + "/callback",
)) as BackendResponse<{
callback_url: string;
}>;
@ -26,7 +26,7 @@ export const submitProviderCallback = async (
const responseProvision = (await backendFetch(
`${authClientCallbackUrl.data?.callback_url!}?callbackURI=${
process.env.APP_URL
}${process.env[envKey]}&${queries}`
}${process.env[envKey]}&${queries}`,
)) as BackendResponse<{
authToken: string;
}>;

View File

@ -1,14 +1,14 @@
"use client";
import { Spinner } from "@/shared/libs/shadcn/ui/spinner";
import { submitProviderCallback } from "@/features/authCallback/actions/submitProviderCallback";
import { useParams, useRouter, useSearchParams } from "next/navigation";
import { useParams, useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";
const AuthCallbackIndex = () => {
const { name } = useParams();
const queries = useSearchParams().toString();
const [textDescription, setTextDescription] = useState(
"We are processing your authentication."
"We are processing your authentication.",
);
const finishOAuthFlow = (type: string) => {
@ -26,6 +26,7 @@ const AuthCallbackIndex = () => {
setTextDescription("Authentication successful! Redirecting...");
finishOAuthFlow("oauth-success");
} else {
console.error("Error in authentication callback:", response);
setTextDescription("Authentication failed. Please try again.");
finishOAuthFlow("oauth-failed");
}