I have been trying to implement both sign in and Google sign in in a new app that I have been building. But I have been receiving this error. Can someone assist me on this please?
Here is the code for my Login.swift file.
import SwiftUI
import AuthenticationServices
import GoogleSignIn
import GoogleSignInSwift
import Firebase
struct Login: View {
// @StateObject var loginModel: LoginViewModel = .init()
@StateObject var loginModel = LoginViewModel()
var body: some View {
ScrollView(.vertical, showsIndicators: false){
VStack(alignment: .leading, spacing: 5){
Image(systemName: "person")
//.clipShape(.Circle)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 75, height: 75)
//.font(.system(size: 40))
.foregroundColor(.black)
.ignoresSafeArea()
(Text("Welcome")
.foregroundColor(.black) +
Text("\n Login to Continue")
.foregroundColor(.secondary)
)
.font(.title)
.fontWeight(.semibold)
.lineSpacing(10)
.padding(.top, 20)
.padding(.trailing, 15)
//Mark Custom Text Field
CustomTextField(hint: "+16505551234", text: $loginModel.mobileNo)
.disabled(loginModel.showOTPField)
.opacity(loginModel.showOTPField ? 0.4 : 1)
.overlay(alignment: .trailing, content:{
Button("Change"){
withAnimation(.easeInOut){
loginModel.showOTPField = false
loginModel.otpCode = ""
loginModel.CLIENT_CODE = ""
}
}
.font(.caption)
.foregroundColor(.indigo)
.opacity(loginModel.showOTPField ? 1 : 0)
.padding(.trailing, 15)
})
.padding(.top, 40)
CustomTextField(hint: "OTP Code", text: $loginModel.otpCode)
.disabled(!loginModel.showOTPField)
.opacity(!loginModel.showOTPField ? 0.4 : 1)
.padding(.top, 20)
Button(action: loginModel.showOTPField ? loginModel.VerifyOTPCode: loginModel.getOTPCode) {
HStack(spacing: 15){
Text(loginModel.showOTPField ? "Verify Code" : "Get OTP")
.fontWeight(.semibold)
.contentTransition(.identity)
Image(systemName: "line.diagonal.arrow")
.font(.title3)
.rotationEffect(.init(degrees: 45))
}
.foregroundColor(.black)
.padding(.horizontal, 25)
.padding(.vertical)
.background{
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(.black.opacity(0.05))
}
.padding(.top, 10)
}
Text("(OR)")
.foregroundColor(.gray)
.frame(maxWidth: .infinity)
.padding(.top,10)
.padding(.bottom, 20)
.padding(.leading, -60)
.padding(.horizontal)
HStack (spacing: 8){
//Mark Space for Apple Sign in
CustomButton()
.overlay{
//Apple Sign in Button
SignInWithAppleButton{ (request) in
//requesting parameter from apple login
loginModel.nonce = randomNonceString()
request.requestedScopes = [.email,.fullName]
request.nonce = sha256(loginModel.nonce)
} onCompletion: { (result) in
switch result{
case .success(let user):
print("Success")
guard let credential = user.credential as? ASAuthorizationAppleIDCredential else{
print("Error with Firebase")
return
}
loginModel.appleAuthenticate(credential: credential)
case .failure(let error):
print(error.localizedDescription)
}
}
.signInWithAppleButtonStyle(.white)
.frame(height: 55)
.blendMode(.overlay)
}
.clipped()
//Mark: Custom Google Sign in Button
//comment from here
CustomButton(isGoogle: true)
.overlay{
if let clientID = FirebaseApp.app()?.options.clientID{
GoogleSignInButton{
GIDSignIn.sharedInstance.signIn(with: .init(clientID: clientID ), presenting: UIApplication.shared.rootController()){
user,error in
if let error = error {
print(error.localizedDescription)
return
}
//Login Google user to firebase
if let user
{
loginModel.logGoogleUser(user: user)
}
}
}
.blendMode(.overlay)
}
}
.clipped()
//comment ends here
}
.padding(.leading, -60)
.frame(maxWidth: .infinity)
}
.padding(.leading,60)
.padding(.vertical,15)
// .blendMode(.overlay)
}
.alert(loginModel.errorMessage, isPresented: $loginModel.showError){
}
}
@ViewBuilder
func CustomButton(isGoogle: Bool = false)-> some View{
HStack{
Group{
if isGoogle{
Image("Google")
.resizable()
.renderingMode(.template)
}else{
Image(systemName: "applelogo")
.resizable()
}
}
.aspectRatio(contentMode: .fit)
.frame(width: 25, height: 25)
.frame(height: 45)
Text("\(isGoogle ? "Google" : "Apple") Sign In")
.font(.callout)
.lineLimit(1)
}
.foregroundColor(.white)
.padding(.horizontal,15)
.background{
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(.black)
}
}
}
struct Login_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
I wanted to lay over sign in and also Google sign in next to each other in HSTACK.
Let me know if you want to look at the whole code happy to share as it is already uploaded in the Git but on private at the moment.