Skip to content

Commit

Permalink
Merge pull request #837 from palladiumkenya/prod
Browse files Browse the repository at this point in the history
Prod update
  • Loading branch information
cbrianbet authored Dec 4, 2024
2 parents c72b368 + 6df8dfc commit bc13d0b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@
"styled-components": "^5.1.1"
},
"scripts": {
"start": "react-scripts --openssl-legacy-provider start",
"start": "react-scripts start",
"start:dev": "env-cmd -f ./.env.development react-scripts start",
"start:prod": "env-cmd -f ./.env.production react-scripts start",
"start:nascop": "env-cmd -f ./.env.nascop react-scripts start",
"build": "react-scripts build",
"build:testing": "env-cmd -f ./.env.testing react-scripts build",
"build:nascop": "env-cmd -f ./.env.nascop react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"postinstall": "semantic-ui-css-patch"
},
"eslintConfig": {
"extends": "react-app"
Expand All @@ -89,6 +90,7 @@
]
},
"devDependencies": {
"@semantic-ui-react/css-patch": "^1.1.2",
"prettier": "^3.3.3",
"react-syntax-highlighter": "^15.5.0"
},
Expand Down
4 changes: 2 additions & 2 deletions src/services/UserService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let config = {};
if(process.env) {
config = {
authority: process.env.REACT_APP_AUTHORITY,
client_id: process.env.REACT_APP_CLIENT,
client_id: "nascop.spa",
redirect_uri: process.env.REACT_APP_REDIRECT_URI,
response_type: 'id_token token',
scope: process.env.REACT_APP_SCOPE,
Expand All @@ -16,7 +16,7 @@ if(process.env) {
} else {
// client_id: process.env.REACT_APP_CLIENT,
config = {
authority: "https://auth.kenyahmis.org/dwhidentity",
authority: "https://identity.kenyahmis.org/nascop",
client_id: "dwh.spa",
redirect_uri: "https://data.kenyahmis.org:9000/#/signin-oidc#",
response_type: "id_token token",
Expand Down
73 changes: 73 additions & 0 deletions src/services/UserService.js.save
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { UserManager } from 'oidc-client';
import { storeUser, storeUserError } from '../actions/Shared/AuthActions';
let config = {};

if(process.env) {
config = {
authority: process.env.REACT_APP_AUTHORITY,
client_id: "nascop.spa",
redirect_uri: process.env.REACT_APP_REDIRECT_URI,
response_type: 'id_token token',
scope: process.env.REACT_APP_SCOPE,
post_logout_redirect_uri:
process.env.REACT_APP_POST_LOGOUT_REDIRECT_URI,
filterProtocolClaims: process.env.REACT_APP_FILTER_PROTOCOL_CLAIMS,
};
} else {
// client_id: process.env.REACT_APP_CLIENT,
config = {
authority: "https://auth.kenyahmis.org/dwhidentity",
client_id: "dwh.spa",
redirect_uri: "https://data.kenyahmis.org:9000/#/signin-oidc#",
response_type: "id_token token",
scope: "openid profile apiApp",
post_logout_redirect_uri: "https://data.kenyahmis.org:9000",
}
}

const userManager = new UserManager(config);

export async function loadUserFromStorage(store) {
try {
let user = await userManager.getUser();
if (!user) { return store.dispatch(storeUserError()); }
store.dispatch(storeUser(user));
} catch (e) {
console.error(`User not found: ${e}`)
store.dispatch(storeUserError())
}
}

export function signinRedirect() {
return userManager.signinRedirect();
}

export function signinRedirectCallback() {
if (window.location.hash) {
try {
return userManager.signinRedirectCallback();
}
catch (e) {
console.log(e);
}
} else {
return userManager.signinRedirectCallback();
}
}

export async function signoutRedirect() {
let user = await userManager.getUser();
await userManager.clearStaleState();
await userManager.removeUser();
return userManager.signoutRedirect({ 'id_token_hint': user.id_token });
}

export function signoutRedirectCallback() {
userManager.clearStaleState();
userManager.removeUser();
return userManager.signoutRedirectCallback();
}

export default userManager;


0 comments on commit bc13d0b

Please sign in to comment.