🚩 complete oauth process
Complete the OAuth process by adding a redirect when pressing the login button with the provider. When the button is pressed, the system will request the authentication URL from the backend, then the user will be redirected.
This commit is contained in:
26
features/auth/lib/requestOauthUrl.ts
Normal file
26
features/auth/lib/requestOauthUrl.ts
Normal file
@ -0,0 +1,26 @@
|
||||
"use server";
|
||||
|
||||
import { api } from "@/shared/api/connector";
|
||||
import { redirect } from "next/navigation";
|
||||
import { ResponseRequestOauthUrl } from "../types/responseRequestOauthUrl";
|
||||
|
||||
const requestOauthUrl = async (requestEndpoint: string) => {
|
||||
// Check if requestEndpoint is provided, if not throw an error
|
||||
if (!requestEndpoint) throw new Error("oAuth endpoint request not found");
|
||||
|
||||
// Define a variable to hold the OAuth data
|
||||
let oauthData: Promise<ResponseRequestOauthUrl>;
|
||||
|
||||
// Fetch OAuth data from the API
|
||||
try {
|
||||
const response = await api.get(requestEndpoint);
|
||||
oauthData = response.json<ResponseRequestOauthUrl>();
|
||||
} catch (error) {
|
||||
throw new Error(JSON.stringify(error));
|
||||
}
|
||||
|
||||
// Redirect to the OAuth provider's authorization page
|
||||
redirect((await oauthData).data);
|
||||
};
|
||||
|
||||
export default requestOauthUrl;
|
||||
Reference in New Issue
Block a user