fix: 🐛 Fulfix. Login funkar

This commit is contained in:
Kajetan Kazimierczak 2022-04-11 22:20:22 +02:00
parent c5302b0dff
commit c5bec5f9ee
5 changed files with 41 additions and 38 deletions

View File

@ -54,7 +54,6 @@ const LoginMethods: Logins = {
BANKID_SAME_DEVICE: 0,
BANKID_ANOTHER_DEVICE: 2,
TEST_USER: 3,
}
export const Login = () => {
@ -122,11 +121,11 @@ export const Login = () => {
}
}
const openFreja = (token:string) => {
const openFreja = (token: string) => {
try {
const originAppScheme = encodeURIComponent(schema);
const originAppScheme = encodeURIComponent(schema)
const frejaUrl =
Platform.OS === 'ios'
Platform.OS === 'ios'
? `${token}&originAppScheme=${originAppScheme}`
: `${token}&originAppScheme=${originAppScheme}`
Linking.openURL(frejaUrl)
@ -140,22 +139,24 @@ export const Login = () => {
(loginMethodId === 'thisdevice' && !loginBankIdSameDeviceWithoutId)
const startLogin = async (text: string) => {
if(loginMethodId === 'freja'){
if (loginMethodId === 'freja') {
showModal(true)
const status = await api.loginFreja();
const status = await api.loginFreja()
setCancelLoginRequest(() => () => status.cancel())
openFreja(status.token)
status.on('STARTED', () => console.log('Freja eID app not yet opened'))
status.on('DELIVERED_TO_MOBILE', () => console.log('Freja eID app is open'))
status.on('CANCELLED', () => {
status.on('DELIVERED_TO_MOBILE', () =>
console.log('Freja eID app is open')
)
status.on('CANCELLED', () => {
console.log('User pressed cancel in Freja eID')
showModal(false)
})
status.on('APPROVED', () => console.log('Freja eID ok'))
}
else if (loginMethodId === 'thisdevice' || loginMethodId === 'otherdevice') {
} else if (
loginMethodId === 'thisdevice' ||
loginMethodId === 'otherdevice'
) {
showModal(true)
let ssn

View File

@ -7,7 +7,11 @@ export type ChildPersonalNumbers = Record<string, string>
export const settingsState = proxy({
hydrated: false,
settings: {
loginMethodId: 'thisdevice' as 'thisdevice' | 'otherdevice' | 'testuser' | 'freja',
loginMethodId: 'thisdevice' as
| 'thisdevice'
| 'otherdevice'
| 'testuser'
| 'freja',
usingSystemTheme: true,
theme: 'light',
cachedPersonalIdentityNumber: '',

View File

@ -201,10 +201,7 @@ export class ApiSkolplattformen extends EventEmitter implements Api {
this.isLoggedIn = true
this.emit('login')
})
// status.on('ERROR', () => {
// this.personalNumber = undefined
// })
return status
}
@ -244,27 +241,28 @@ export class ApiSkolplattformen extends EventEmitter implements Api {
}
private async retrieveFrejaSessionCookie(): Promise<void> {
const url = routes.frejaLoginCookie
const session = await this.getSession(url, {
redirect: 'manual',
})
//const session = this.getRequestInit()
console.log(JSON.stringify(session))
const response = await this.fetch('freja-login-return-url', url, session)
console.log(response.status)
console.log(response.text())
console.log(JSON.stringify(response))
const response2 = await this.fetch('freja-login-cookie', url, session)
console.log(response2.status)
console.log(response2.text())
try{
const url = routes.frejaReturnUrl
const session = await this.getSession(url, {
redirect: 'manual',
})
await this.fetch('freja-login-return-url', url, session)
} catch(error){
console.log(JSON.stringify(error))
}
try{
const url2 = routes.frejaLoginCookie
const session = await this.getSession(url2, {
redirect: 'manual',
})
await this.fetch('freja-login-cookie', url2, session)
} catch(error2){
console.log(JSON.stringify(error2))
}
}
private async retrieveXsrfToken(): Promise<void> {
const url = routes.hemPage
const session = this.getRequestInit()

View File

@ -25,7 +25,7 @@ export class FrejaChecker extends EventEmitter implements FrejaLoginStatusChecke
this.emit(status);
if (!this.cancelled &&
status !== 'APPROVED' &&
// status !== 'ERROR!' &&
status !== 'ERROR' &&
status !== 'CANCELLED'
){
setTimeout(() => this.check(), 1000);

View File

@ -19,7 +19,7 @@ export interface LoginStatusChecker {
export interface FrejaLoginStatusChecker {
token: string
on: (
event: 'APPROVED' | 'STARTED' | 'DELIVERED_TO_MOBILE' | 'CANCELLED',
event: 'APPROVED' | 'STARTED' | 'UNKNOWN' | 'DELIVERED_TO_MOBILE' | 'CANCELLED' | 'EXPIRED' | 'RP_CANCELED' | 'ERROR',
listener: (...args: any[]) => void
) => FrejaLoginStatusChecker
cancel: () => Promise<void>