Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions app/api/auth/[...nextauth]/authOptions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// app/api/auth/[...nextauth]/authOptions.ts
import GitHub from "next-auth/providers/github";
import type { NextAuthOptions } from "next-auth";
import { checkOnboardingStatus } from "@/services/onboarding/OnboardingService";
import { getAuthDataByGithubUsername } from "@/services/user/UserService";
import { checkOnboardingStatus, getAuthDataByGithubUsername } from "@/services/onboarding/DataForgeAuthHelperService";

export const authOptions: NextAuthOptions = {
providers: [
Expand Down Expand Up @@ -126,12 +125,10 @@ export const authOptions: NextAuthOptions = {

try {
// Check onboarding status first
const onboardingStatus = await checkOnboardingStatus(githubUsername);

const onboardingStatus = await checkOnboardingStatus(githubUsername, true);
if (onboardingStatus.onboarded) {
// User is onboarded - fetch auth credentials
const authData = await getAuthDataByGithubUsername(githubUsername);

const authData = await getAuthDataByGithubUsername(githubUsername, true);
newToken.user_id = authData.user_id;
newToken.profile_id = authData.profile_id;
newToken.github_user_name = githubUsername;
Expand Down Expand Up @@ -167,12 +164,11 @@ export const authOptions: NextAuthOptions = {
// This runs on every JWT callback invocation (session refresh)
if (token.github_user_name) {
try {
const onboardingStatus = await checkOnboardingStatus(token.github_user_name);
const onboardingStatus = await checkOnboardingStatus(token.github_user_name, true);

if (onboardingStatus.onboarded) {
// User is now onboarded - fetch auth credentials
const authData = await getAuthDataByGithubUsername(token.github_user_name);

const authData = await getAuthDataByGithubUsername(token.github_user_name, true);
token.user_id = authData.user_id;
token.profile_id = authData.profile_id;
token.requires_onboarding = false;
Expand Down
2 changes: 1 addition & 1 deletion app/onboarding/steps/step-career.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from "./shared-constants";
import type { StepProps } from "@/types/client/onboarding/onboarding";
import type { StepId } from "@/lib/Zustand/onboarding-store";
import { checkOnboardingStatus, submitOnboarding } from "@/services/onboarding/OnboardingService";
import { checkOnboardingStatus, submitOnboarding } from "@/services/onboarding/DataForgeAuthHelperService";
import { OnboardUserRequest } from "@/types/server/dataforge/User/user";

interface CareerStepProps extends StepProps {
Expand Down
3 changes: 0 additions & 3 deletions components/profile/profile-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ export function ProfileContainer() {
return newSet;
});
};

console.log("Session", session);

return (
<div className="max-w-8xl mx-auto space-y-6">
{/* Header */}
Expand Down
16 changes: 8 additions & 8 deletions services/CoreApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ export type ApiServiceKey = "dataforge" | "gitripper" | "helios" | "archivist" |
export async function apiCall<T = unknown>(
service: ApiServiceKey,
path: string | string[],
init?: RequestInit
init?: RequestInit,
isFromServer: boolean = false
): Promise<T> {
const pathStr =
typeof path === "string"
? path.replace(/^\/+|\/+$/g, "")
: path.map((s) => String(s).replace(/^\/+|\/+$/g, "")).join("/");
const fullPath = `${service}/${pathStr}`;
let url = `/api/${fullPath}`;
const method = init?.method ?? "GET";
const base =
typeof window === "undefined"
? process.env.NEXTAUTH_URL
: "";

url = `${base}/api/${fullPath}`;
let url = "";
if (isFromServer == true) {
url = `${process.env.NEXT_PUBLIC_DATAFORGE_SERVICE_URL}/${pathStr}`;
} else {
url = `/api/${fullPath}`;
}
const response = await fetch(url, {
...init,
method,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,53 @@
import { apiCall } from "@/services/CoreApiService";
import type {
CheckOnboardingStatusResponse,
GetAuthDataResponse,
OnboardUserRequest,
OnboardUserResponse,
} from "@/types/server/dataforge/User/user";

const ONBOARD_PATH = "Dijkstra/v1/u/onboard";
const USER_PATH = "Dijkstra/v1/u";

/**
* Check onboarding status for a username
*/
export async function checkOnboardingStatus(
username: string
username: string,
isFromServer: boolean = false
): Promise<CheckOnboardingStatusResponse> {
return apiCall<CheckOnboardingStatusResponse>(
"dataforge",
`${ONBOARD_PATH}?username=${encodeURIComponent(username)}`
`${ONBOARD_PATH}?username=${encodeURIComponent(username)}`,
undefined,
isFromServer
);
}

/**
* Submit onboarding data
*/
export async function submitOnboarding(
data: OnboardUserRequest
data: OnboardUserRequest,
isFromServer: boolean = false
): Promise<OnboardUserResponse> {
return apiCall<OnboardUserResponse>("dataforge", ONBOARD_PATH, {
method: "POST",
body: JSON.stringify(data),
});
}, isFromServer);
}

/**
* Get Auth Data by GitHub username
*/
export async function getAuthDataByGithubUsername(
username: string,
isFromServer: boolean = false
): Promise<GetAuthDataResponse> {
return apiCall<GetAuthDataResponse>(
"dataforge",
`${USER_PATH}/auth/${encodeURIComponent(username)}`,
undefined,
isFromServer
);
}
15 changes: 0 additions & 15 deletions services/user/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import type {
GetUserBasicResponse,
GetUserSideCardResponse,
} from "@/types/server/dataforge/User/user";
import type { GetPersonalDetailsResponse } from "@/types/server/dataforge/User/profile";
import type { PersonalDetailsData } from "@/types/client/profile-section/profile-sections";
import { transformPersonalDetails } from "@/services/profile/transformers/transformers";

const USER_PATH = "Dijkstra/v1/u";

Expand All @@ -34,16 +31,4 @@ export async function getSideCardDetailsByGithubUsername(
"dataforge",
`${USER_PATH}/card/${encodeURIComponent(username)}`
);
}

/**
* Get Auth Data by GitHub username
*/
export async function getAuthDataByGithubUsername(
username: string
): Promise<GetAuthDataResponse> {
return apiCall<GetAuthDataResponse>(
"dataforge",
`${USER_PATH}/auth/${encodeURIComponent(username)}`
);
}