Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shiksha 2.0 Auth login + content list. #46

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions apps/shiksha-app/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'use client';

import { useEffect, useState } from 'react';
import { useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { CircularProgress, Box } from '@mui/material';

export default function AuthCheck() {
const router = useRouter();
const [loading, setLoading] = useState(true);
const URL_CONTENT = process.env.NEXT_PUBLIC_CONTENT;
const URL_LOGIN = process.env.NEXT_PUBLIC_LOGIN;

Expand Down
3 changes: 2 additions & 1 deletion mfes/content/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const { composePlugins, withNx } = require('@nx/next');

const PORTAL_BASE_URL = 'https://sunbird-editor.tekdinext.com';
const basePath = process.env.NEXT_PUBLIC_ASSETS_CONTENT || '/mfe_content';

const routes = {
API: {
Expand All @@ -25,7 +26,7 @@ const nextConfig = {
svgr: false,
},

basePath: '/mfe_content', // This should match the path set in Nginx
basePath, // This should match the path set in Nginx

async rewrites() {
return [
Expand Down
11 changes: 6 additions & 5 deletions mfes/content/src/pages/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import HelpIcon from '@mui/icons-material/Help';
import { SelectChangeEvent } from '@mui/material';
import { trackingData } from '../services/TrackingService';
import AppConst from '../utils/AppConst/AppConst';
interface ContentItem {
name: string;
gradeLevel: string[];
Expand Down Expand Up @@ -248,7 +249,7 @@ export default function Content() {
'application/vnd.sunbird.questionset',
].includes(contentMimeType)
) {
await contentReadAPI(identifier);
// await contentReadAPI(identifier);
router.push(`/player/${identifier}`);
} else {
const result = await hierarchyAPI(identifier);
Expand All @@ -264,7 +265,7 @@ export default function Content() {
setIsLoading(false);
}
};
``;

useEffect(() => {
const handleScroll = () => {
setShowBackToTop(window.scrollY > 300);
Expand Down Expand Up @@ -294,7 +295,7 @@ export default function Content() {
image={
item?.posterImage && item?.posterImage !== 'undefined'
? item?.posterImage
: '/assests/images/image_ver.png'
: `${AppConst.BASEPATH}/assests/images/image_ver.png`
}
content={item?.description || '-'}
// subheader={item?.contentType}
Expand All @@ -320,7 +321,7 @@ export default function Content() {
{isLoading ? 'Loading...' : 'Load More'}
</Button>
) : (
<Typography variant="body1" color="textSecondary">
<Typography variant="body1" color="black">
No more data available
</Typography>
)}
Expand Down Expand Up @@ -411,7 +412,7 @@ export default function Content() {
}, [router]);
const fetchFramework = async () => {
try {
const url = `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/api/framework/v1/read/${process.env.NEXT_PUBLIC_FRAMEWORK}`;
const url = `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/interface/v1/api/framework/v1/read/${process.env.NEXT_PUBLIC_FRAMEWORK}`;
const frameworkData = await fetch(url).then((res) => res.json());
const frameworks = frameworkData?.result?.framework;
setFrameworkFilter(frameworks);
Expand Down
5 changes: 3 additions & 2 deletions mfes/content/src/services/Read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ export const contentReadAPI = async (doId: string) => {
const config: AxiosRequestConfig = {
method: 'get',
maxBodyLength: Infinity,
url: `${searchApiUrl}/api/content/v1/read/` + doId,
url: `${searchApiUrl}/interface/v1/action/content/v3/read/` + doId,
headers: {
Authorization: `'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0WEZYTWFVOWFBanpUbk5aSXNySEpyV0hwVW94bzY3NyJ9.WSWVtVh5MCH_yymFEM_qpVzXGdDO5mukrqmIii1C5Ww'`,
tenantId: localStorage.getItem('tenantId') || '',
Authorization: `Bearer ${localStorage.getItem('accToken') || ''}`,
},
};
console.log('config', config);
Expand Down
2 changes: 1 addition & 1 deletion mfes/content/src/services/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const ContentSearch = async (
const config: AxiosRequestConfig = {
method: 'post',
maxBodyLength: Infinity,
url: `${searchApiUrl}/api/content/v1/search`,
url: `${searchApiUrl}/interface/v1/action/composite/v3/search`,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

API endpoint updated to v3

The URL has been updated from /api/content/v1/search to /interface/v1/action/composite/v3/search, indicating a version upgrade. This change aligns with similar updates in other files.


🏁 Script executed:

#!/bin/bash
# Verify if this new API endpoint is used consistently across the codebase

# Check for any remaining references to the old API endpoint pattern
echo "Checking for any references to old API endpoint pattern..."
rg -i "/api/content/v1/search" --type ts

# Check for consistent usage of the new endpoint pattern
echo "Checking usage of new endpoint pattern..."
rg -i "/interface/v1/action/composite/v3/search" --type ts

Length of output: 634


Attention: Inconsistent API Endpoint Versions
The update in mfes/content/src/services/Search.ts correctly changes the endpoint to /interface/v1/action/composite/v3/search. However, our verification shows that the following files still reference the old endpoint (/api/content/v1/search):

  • libs/shared-lib/src/lib/Services/Content/Hierarchy.ts
  • libs/shared-lib/src/lib/Services/Content/Search.ts

Please update these files to use the new API endpoint for consistency across the codebase.

data: data,
};

Expand Down
5 changes: 5 additions & 0 deletions mfes/content/src/utils/AppConst/AppConst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const AppConst = {
BASEPATH: process.env.NEXT_PUBLIC_ASSETS_CONTENT || '/mfe_content',
};

export default AppConst;
8 changes: 7 additions & 1 deletion mfes/players/src/services/PlayerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ export const fetchContent = async (identifier: any) => {
const LICENSE_DETAILS = URL_CONFIG.PARAMS.LICENSE_DETAILS;
const MODE = 'edit';
const response = await axios.get(
`${API_URL}?fields=${FIELDS}&mode=${MODE}&licenseDetails=${LICENSE_DETAILS}`
`${API_URL}?fields=${FIELDS}&mode=${MODE}&licenseDetails=${LICENSE_DETAILS}`,
{
headers: {
tenantId: localStorage.getItem('tenantId') || '',
Authorization: `Bearer ${localStorage.getItem('accToken') || ''}`,
},
}
);
console.log('response =====>', response);
return response?.data?.result?.content;
Expand Down
2 changes: 1 addition & 1 deletion mfes/players/src/utils/url.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const URL_CONFIG = {
HIERARCHY_FEILDS: 'instructions,outcomeDeclaration',
},
API: {
CONTENT_READ: `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/api/content/v1/read/`,
CONTENT_READ: `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/interface/v1/action/content/v3/read/`,
HIERARCHY_API: `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/action/questionset/v2/hierarchy/`,
QUESTIONSET_READ: `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/action/questionset/v2/read/`,
COMPOSITE_SEARCH: `${process.env.NEXT_PUBLIC_SSUNBIRD_BASE_URL}/action/composite/v3/search`,
Expand Down
4 changes: 3 additions & 1 deletion mfes/registration/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { composePlugins, withNx } = require('@nx/next');
const BASE_PATH =
process.env.NEXT_PUBLIC_ASSETS_REGISTRATION || '/mfe_registration';

/**
* @type {import('@nx/next/plugins/with-nx').WithNxOptions}
Expand All @@ -13,7 +15,7 @@ const nextConfig = {
svgr: false,
},

basePath: '/mfe_registration', // This should match the path set in Nginx
basePath: BASE_PATH, // This should match the path set in Nginx
};

const plugins = [
Expand Down
87 changes: 41 additions & 46 deletions mfes/registration/src/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
'use client';
import React, { useState } from 'react';
import { Button, Typography } from '@mui/material';
import VisibilityIcon from '@mui/icons-material/Visibility';
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
import { AlertTitle, Button } from '@mui/material';
import Alert from '@mui/material/Alert';
import CircularProgress from '@mui/material/CircularProgress';
import Grid from '@mui/material/Grid2';
import {
CommonCheckbox,
CommonSelect,
CommonTextField,
Layout,
// login,
} from '@shared-lib';
import { SelectChangeEvent } from '@mui/material/Select';
import Link from 'next/link';
import { getToken } from '../../services/LoginService';
import { useRouter } from 'next/navigation';
// import { SelectChangeEvent } from '@mui/material/Select';
import { CommonTextField, Layout } from '@shared-lib';
import { jwtDecode } from 'jwt-decode';
const languageData = [
{ id: 1, name: 'English' },
{ id: 2, name: 'Marathi' },
{ id: 3, name: 'Hindi' },
];

const checkboxData = [{ label: 'Remember Me' }];
import { useRouter } from 'next/navigation';
import React, { useState } from 'react';
import { login } from '../../services/LoginService';
import AppConst from '../../utils/AppConst/AppConst';

export default function Login() {
const [formData, setFormData] = useState({
Expand All @@ -35,11 +22,10 @@ export default function Login() {
userName: false,
password: false,
});
const [selectedValue, setSelectedValue] = useState('english');
const [checked, setChecked] = useState(false);
// const [selectedValue, setSelectedValue] = useState('english');
// const [checked, setChecked] = useState(false);
const [showPassword, setShowPassword] = useState(false);
const [showError, setShowError] = useState(false);
const [errorMessage, setErrorMessage] = useState('');
const [errorMessage, setErrorMessage] = useState<string[]>([]);
const [loading, setLoading] = useState(false);
const router = useRouter();
const handleChange =
Expand All @@ -55,16 +41,16 @@ export default function Login() {
});
};

const handleCheckboxChange = (
event: React.ChangeEvent<HTMLInputElement>,
checked: boolean,
label: string
) => {
setChecked(checked);
console.log(
`Checkbox '${label}' is now ${checked ? 'checked' : 'unchecked'}`
);
};
// const handleCheckboxChange = (
// event: React.ChangeEvent<HTMLInputElement>,
// checked: boolean,
// label: string
// ) => {
// setChecked(checked);
// console.log(
// `Checkbox '${label}' is now ${checked ? 'checked' : 'unchecked'}`
// );
// };

const handleButtonClick = async () => {
if (!formData.userName || !formData.password) {
Expand All @@ -76,14 +62,15 @@ export default function Login() {
}
setLoading(true);
try {
const response = await getToken({
const { result: response, authUser } = await login({
username: formData.userName,
password: formData.password,
});

if (response?.access_token) {
if (response?.access_token && authUser?.tenantData?.[0]?.tenantId) {
localStorage.setItem('accToken', response?.access_token);
localStorage.setItem('refToken', response?.refresh_token);
localStorage.setItem('tenantId', authUser?.tenantData?.[0]?.tenantId);
const decoded = jwtDecode(response?.access_token);
const subId = decoded?.sub?.split(':')[2];
document.cookie = `subid=${subId}; path=/;`;
Expand All @@ -92,21 +79,23 @@ export default function Login() {
router.push(redirectUrl);
}
} else {
setShowError(true);
setErrorMessage(response);
if (!response?.access_token) {
setErrorMessage(['Invalid tenantId or access token']);
} else if (!authUser?.tenantData?.[0]?.tenantId) {
setErrorMessage(['Invalid tenantId']);
}
}
} catch (error: any) {
console.error('Login failed:', error);
setShowError(true);
setErrorMessage(error);
setErrorMessage([error.message, error?.response?.data?.params?.errmsg]);
} finally {
setLoading(false);
}
};

const handleSelectChange = (event: SelectChangeEvent) => {
setSelectedValue(event.target.value);
};
// const handleSelectChange = (event: SelectChangeEvent) => {
// setSelectedValue(event.target.value);
// };

return (
<Layout
Expand Down Expand Up @@ -140,7 +129,7 @@ export default function Login() {
}}
>
<img
src="/assets/images/logo-tekdi.png"
src={`${AppConst.BASEPATH}/assets/images/logo-tekdi.png`}
alt="Company Logo"
style={{ maxWidth: '100%', height: 'auto' }}
/>
Expand All @@ -157,6 +146,7 @@ export default function Login() {
padding: '15px',
backgroundColor: '#FFFFFF',
}}
justifyContent={{ sm: 'center', md: 'center' }}
>
{/* <CommonSelect
label=""
Expand Down Expand Up @@ -242,9 +232,14 @@ export default function Login() {
</Typography> */}
</Grid>
</Grid>
{showError && (
{Array.isArray(errorMessage) && errorMessage.length > 0 && (
<Alert variant="filled" severity="error">
{errorMessage}
<AlertTitle>Error</AlertTitle>
<ul style={{ margin: 0, paddingInlineStart: '15px' }}>
{errorMessage.map((error) => (
<li key={error}>{error}</li>
))}
</ul>
</Alert>
)}
</Layout>
Expand Down
Loading