In my app I have the user login with their google account to have the rest of the app personalized to their account, however after they login I want to have it automatically change views and go to the home screen, but I have not found a way to make it work without have a separate button that needs to be tapped after login to change the view.
Here is the code for the login page. I'm currently changing the view with a NavigationLink
, but I would like to know a way to do it automatically after a user is signed in.
struct LoginPage: View {
var body: some View {
//Login Page
NavigationView{
ScrollView {
VStack {
VLargeCardView(image: "pad22finalsf", category: "Login", heading: "Welcome to PV Pocket!", author: "PAD22")
//Google Sign In Button
google()
.frame(width: 200, height: 50)
//Switch to main view after login
NavigationLink(destination: MainView()) {
ZStack {
Rectangle()
.frame(width: 300, height: 50)
.cornerRadius(20)
.foregroundColor(.orange)
Text("Click here after sign in!")
.foregroundColor(.primary)
.font(Font.system(size: 25))
}
}
.navigationBarHidden(true) .navigationBarTitle("")
}
}
}
}
}
If it helps here is the code for the Google sign in button as well.
//Creates Google Sign In instance
struct google : UIViewRepresentable {
@EnvironmentObject var settings: UserSettings
func makeUIView(context: UIViewRepresentableContext<google>) -> GIDSignInButton {
//Create Google Sign In Button
let button = GIDSignInButton()
button.colorScheme = .dark
button.style = .wide
//Add Scopes to Login
GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/drive")
GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/classroom.courses")
GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/classroom.coursework.me")
GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/calendar")
//Restore Previous Login if it exists
GIDSignIn.sharedInstance()?.restorePreviousSignIn()
GIDSignIn.sharedInstance()?.presentingViewController = UIApplication.shared.windows.last?.rootViewController
return button
}
func updateUIView(_ uiView: GIDSignInButton, context: UIViewRepresentableContext<google>) {
}
}
Any help or info would be greatly appreciated!