Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Networking/Sources/Networking/Requests/FirebaseLoginRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Foundation

// MARK: - FirebaseLoginResponse
public struct FirebaseLoginResponse: Codable {
let kind, localID, email, displayName: String
let idToken: String
let registered: Bool
let refreshToken, expiresIn: String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expiresIn should be converted to Date

}

// MARK: - FirebaseLoginRequest
public struct FirebaseLoginRequest: RequestType {
Comment on lines +4 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public struct FirebaseLoginResponse: Codable {
let kind, localID, email, displayName: String
let idToken: String
let registered: Bool
let refreshToken, expiresIn: String
}
// MARK: - FirebaseLoginRequest
public struct FirebaseLoginRequest: RequestType {
public struct LoginResponse: Codable {
let email, displayName: String
let idToken: String
let registered: Bool
let refreshToken, expiresIn: String
}
// MARK: - FirebaseLoginRequest
public struct LoginRequest: RequestType {

public typealias ResponseType = FirebaseLoginResponse

private let email: String
private let password: String

public init(email: String, password: String) {
self.email = email
self.password = password
}

public var baseUrl: URL { Constants.firebaseAuth }
public var path: String { "AIzaSyB0UczrurqM1STyI8tvx4QZVTyQVw4UJ7Q" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no the path... pease check the register request as an example

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i get a little confused about that

public var method: String = "POST"
Copy link
Collaborator Author

@a7maad-ayman a7maad-ayman Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it right to pass the apiKey for the path
or should it be act like a query parameter
@ahmdmhasn

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I have actually written the Unit tests last week. I've been waiting for your approval 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please unit test this clss to make sure the parameters and other values are sent as expected

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You either use

Suggested change
public var method: String = "POST"
public var method: String { "POST" }

or

Suggested change
public var method: String = "POST"
public let method: String = "POST"

public var queryParameters: [String: String] {
[
"email": email,
"password": password
]
}
public var headers: [String : String] {
[ "Content-Type": "application/json" ]
}

public let responseDecoder: (Data) throws -> FirebaseLoginResponse = { data in
try JSONDecoder().decode(ResponseType.self, from: data)
}
}