Skip to content

Commit

Permalink
Merge pull request #5 from kolplattformen/fix/start-bankid
Browse files Browse the repository at this point in the history
fixes auto-start of BankID
  • Loading branch information
ErikHellman authored Dec 19, 2020
2 parents 827a049 + 66a8fbe commit 6a3119d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/app/components/login.component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect } from 'react';
import { Platform } from 'react-native';
import { SafeAreaView, StyleSheet, Image, Linking } from 'react-native';
import { Button, Icon, Modal, Card, Text, ImageBackground, Divider, Layout, TopNavigation, Input } from '@ui-kitten/components';
import Personnummer from 'personnummer'
Expand All @@ -18,7 +19,8 @@ export const Login = ({ navigation }) => {

useEffect(() => {
setValid(Personnummer.valid(socialSecurityNumber))
//setHasBankId(Linking.canOpenURL('bankid://'))
const url = Platform.OS == 'ios' ? 'https://app.bankid.com/' : 'bankid:///';
setHasBankId(Linking.canOpenURL(url))
}, [socialSecurityNumber])

useEffect(() => {
Expand Down Expand Up @@ -62,7 +64,9 @@ export const Login = ({ navigation }) => {
const token = await fetch(`${baseUrl}/login?socialSecurityNumber=${socialSecurityNumber}`, {method: 'POST'}).then(res => res.json())

console.log('got token', token)
try {if (hasBankId) Linking.openURL(`bankid:///?autostarttoken=${token.token}`)} catch(err){ setHasBankId(false)}
const bankIdUrl = Platform.OS === 'ios' ? `https://app.bankid.com/?autostarttoken=${token.token}&redirect=null` : `bankid:///?autostarttoken=${token.token}&redirect=null`
console.log(`Open BankID: ${bankIdUrl}`)
try {if (hasBankId) Linking.openURL(bankIdUrl)} catch(err){ setHasBankId(false)}
const jwt = await fetch(`${baseUrl}/login/${token.order}/jwt`, {timeoutInterval: 60000}).then(res => res.ok ? res : Promise.reject(res.json())).then(res => res.json())
await setJwt(jwt.token || jwt)
setVisible(false)
Expand Down
Binary file not shown.

0 comments on commit 6a3119d

Please sign in to comment.