bugfix from breaking changes in jwt PR
This commit is contained in:
parent
c0cfbf097f
commit
0d2dbcaa14
|
@ -49,11 +49,10 @@ api.register({
|
||||||
try {
|
try {
|
||||||
const cookie = await backend.waitForToken({order})
|
const cookie = await backend.waitForToken({order})
|
||||||
const token = createToken(cookie)
|
const token = createToken(cookie)
|
||||||
|
return res.status(200).json({token})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res.status(500).json({err})
|
return res.status(500).json({err})
|
||||||
}
|
}
|
||||||
console.log('login succeeded')
|
|
||||||
return res.status(200).json({token})
|
|
||||||
},
|
},
|
||||||
getChildren: async (c, req, res) => {
|
getChildren: async (c, req, res) => {
|
||||||
console.log('get children')
|
console.log('get children')
|
||||||
|
|
|
@ -149,7 +149,7 @@ const getSchedule = async (childId, cookie) => {
|
||||||
|
|
||||||
const getClassmates = async (childId, cookie) => {
|
const getClassmates = async (childId, cookie) => {
|
||||||
const url = urls.classmates(childId)
|
const url = urls.classmates(childId)
|
||||||
const classMates = await fetchJson(url, cookie)
|
const classmates = await fetchJson(url, cookie)
|
||||||
|
|
||||||
return classmates
|
return classmates
|
||||||
.map(({
|
.map(({
|
||||||
|
|
|
@ -20,10 +20,12 @@ const test = async () => {
|
||||||
|
|
||||||
const token = await fetch(`http://localhost:9000/login?socialSecurityNumber=${socialSecurityNumber}`, {method: 'POST'}).then(res => res.json())
|
const token = await fetch(`http://localhost:9000/login?socialSecurityNumber=${socialSecurityNumber}`, {method: 'POST'}).then(res => res.json())
|
||||||
// login with BankID
|
// login with BankID
|
||||||
const jwt = await fetch(`http://localhost:9000/login/${token.order}/jwt`).then(res => res.json())
|
const {token: jwt} = await fetch(`http://localhost:9000/login/${token.order}/jwt`).then(res => res.json())
|
||||||
|
console.log('got jwt', jwt)
|
||||||
const headers = {authorization: 'Bearer ' + jwt}
|
const headers = {authorization: 'Bearer ' + jwt}
|
||||||
|
|
||||||
const children = await fetch(`http://localhost:9000/children`, {headers}).then(res => res.json())
|
const children = await fetch(`http://localhost:9000/children`, {headers}).then(res => res.json())
|
||||||
|
console.log('children', children)
|
||||||
const data = await Promise.all(children.map(async child => ({
|
const data = await Promise.all(children.map(async child => ({
|
||||||
...child,
|
...child,
|
||||||
classmates: await fetch(`http://localhost:9000/children/${child.sdsId}/classmates`, {headers}).then(res => res.json()),
|
classmates: await fetch(`http://localhost:9000/children/${child.sdsId}/classmates`, {headers}).then(res => res.json()),
|
||||||
|
|
|
@ -38,8 +38,8 @@ export const Child = ({route, navigation}) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView style={{ flex: 1 }}>
|
<SafeAreaView style={{ flex: 1 }} style={styles.topBar}>
|
||||||
<TopNavigation title={ child.name} alignment='center' accessoryLeft={BackAction} />
|
<TopNavigation title={ child.name} alignment='center' accessoryLeft={BackAction} style={styles.topBar}/>
|
||||||
<TabView selectedIndex={selectedIndex} onSelect={index => setSelectedIndex(index)}>
|
<TabView selectedIndex={selectedIndex} onSelect={index => setSelectedIndex(index)}>
|
||||||
<Tab title="Nyheter" icon={NewsIcon}>
|
<Tab title="Nyheter" icon={NewsIcon}>
|
||||||
<Layout style={styles.tabContainer}>
|
<Layout style={styles.tabContainer}>
|
||||||
|
@ -73,6 +73,10 @@ export const Child = ({route, navigation}) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
|
||||||
|
topBar: {
|
||||||
|
backgroundColor: "#fff"
|
||||||
|
},
|
||||||
tabContainer: {
|
tabContainer: {
|
||||||
alignItems: 'flex-start',
|
alignItems: 'flex-start',
|
||||||
justifyContent: 'flex-start',
|
justifyContent: 'flex-start',
|
||||||
|
|
|
@ -33,7 +33,7 @@ export const Children = ({ navigation }) => {
|
||||||
useEffect(useCallback(() => {
|
useEffect(useCallback(() => {
|
||||||
fetch(`${baseUrl}/children/`, {headers}).then(res => res.json()).then(children => {
|
fetch(`${baseUrl}/children/`, {headers}).then(res => res.json()).then(children => {
|
||||||
// TODO: performance
|
// TODO: performance
|
||||||
Promise.all(children.map(async child => ({
|
Promise.all((children || [] ).map(async child => ({
|
||||||
...child,
|
...child,
|
||||||
classmates: await fetch(`${baseUrl}/children/${child.sdsId}/classmates`, {headers}).then(res => res.json()),
|
classmates: await fetch(`${baseUrl}/children/${child.sdsId}/classmates`, {headers}).then(res => res.json()),
|
||||||
news: await fetch(`${baseUrl}/children/${child.id}/news`, {headers}).then(res => res.json()),
|
news: await fetch(`${baseUrl}/children/${child.id}/news`, {headers}).then(res => res.json()),
|
||||||
|
@ -41,7 +41,7 @@ export const Children = ({ navigation }) => {
|
||||||
schedule: await fetch(`${baseUrl}/children/${child.sdsId}/schedule`, {headers}).then(res => res.json()),
|
schedule: await fetch(`${baseUrl}/children/${child.sdsId}/schedule`, {headers}).then(res => res.json()),
|
||||||
menu: await fetch(`${baseUrl}/children/${child.id}/menu`, {headers}).then(res => res.json()),
|
menu: await fetch(`${baseUrl}/children/${child.id}/menu`, {headers}).then(res => res.json()),
|
||||||
notifications: await fetch(`${baseUrl}/children/${child.sdsId}/notifications`, {headers}).then(res => res.json())
|
notifications: await fetch(`${baseUrl}/children/${child.sdsId}/notifications`, {headers}).then(res => res.json())
|
||||||
}))).then(children => setChildren(children))
|
}))).then(children => console.log(children) || setChildren(children))
|
||||||
})
|
})
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
|
|
@ -65,7 +65,7 @@ export const Login = ({ navigation }) => {
|
||||||
|
|
||||||
console.log('got token', token)
|
console.log('got token', token)
|
||||||
if (hasBankId) Linking.openURL(`bankid:///?autostarttoken=${token.token}`)
|
if (hasBankId) Linking.openURL(`bankid:///?autostarttoken=${token.token}`)
|
||||||
const jwt = await fetch(`${baseUrl}/login/${token.order}/jwt`, {timeoutInterval: 60000}).then(res => res.ok ? res : Promise.reject(res.json())).then(res => res.json())
|
const {token: jwt} = await fetch(`${baseUrl}/login/${token.order}/jwt`, {timeoutInterval: 60000}).then(res => res.ok ? res : Promise.reject(res.json())).then(res => res.json())
|
||||||
console.log('got jwt', jwt)
|
console.log('got jwt', jwt)
|
||||||
await setJwt(jwt)
|
await setJwt(jwt)
|
||||||
setVisible(false)
|
setVisible(false)
|
||||||
|
|
Loading…
Reference in New Issue