Created
February 11, 2019 17:53
-
-
Save pkellner/65dbbe39150f833f07230ebe919652fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
import { IUserInfo } from '../components/codecamp/common/CodeCampInterfaces'; | |
//import getEnvParameters from './getEnvParameter'; | |
//import getConfig from 'next/config'; | |
//const { publicRuntimeConfig } = getConfig(); | |
const fetchUserInfoPromise: Promise<{userInfo: IUserInfo} | {hasErrored: boolean,isServer: boolean,errorMessage: any}> = (cookieValue: string) => { | |
//$$$ TODO: check for cookieValue and if null, just return empty speaker so don't need to do check on every request | |
//const url = getEnvParameters("RESTURL_IS LOGGEDIN"); | |
//let cookieValue = ''; | |
// let url; | |
// if (process.env.NODE_ENV === 'production') { | |
// return ( | |
// process.env.RESTURL_ISLOGGEDIN_PROD || | |
// publicRuntimeConfig.RESTURL_ISLOGGEDIN_DEFAULT | |
// ); | |
// } else { | |
// //return process.env.LOGINAUTH_URL_DEV_YES; // todo: have way to show NO | |
// | |
// } | |
const url = ''; | |
const promise = axios({ | |
url: url, | |
method: 'post', | |
headers: { | |
Cookie: '.ASPXAUTH=' + cookieValue | |
} | |
}) | |
.then(response => { | |
// const x = response.data; | |
// console.log(x); | |
const { | |
id = 0, | |
username = '....', | |
userFirstName = '.', | |
userLastName = '..' | |
} = response.data.attendeeResults; | |
const userInfoObj: IUserInfo = { | |
id, | |
username, | |
userFirstName, | |
userLastName | |
}; | |
return { | |
userInfo: userInfoObj | |
}; | |
}) | |
.catch(error => { | |
// console.log('error:' + error.message); | |
return { | |
hasErrored: true, | |
isServer: true, | |
errorMessage: error.message | |
}; | |
}); | |
return promise; | |
}; | |
export default fetchUserInfoPromise; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment