Skip to content

Commit

Permalink
fix: 🐛 Fulfix. Login funkar
Browse files Browse the repository at this point in the history
  • Loading branch information
kajetan-kazimierczak committed Apr 11, 2022
1 parent c5302b0 commit c5bec5f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 38 deletions.
25 changes: 13 additions & 12 deletions apps/skolplattformen-app/components/login.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const LoginMethods: Logins = {
BANKID_SAME_DEVICE: 0,
BANKID_ANOTHER_DEVICE: 2,
TEST_USER: 3,

}

export const Login = () => {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion apps/skolplattformen-app/hooks/useSettingsStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down
44 changes: 21 additions & 23 deletions libs/api-skolplattformen/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion libs/api-skolplattformen/lib/frejaLoginStatusChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion libs/api/lib/loginStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit c5bec5f

Please sign in to comment.