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

View File

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

View File

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

View File

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

View File

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