basic auth working with google sign in button
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
89288ECB27675B9F00E962C4 /* OnboardingTemplateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89288ECA27675B9F00E962C4 /* OnboardingTemplateView.swift */; };
|
||||
89D99D2E2766FD6B00237814 /* Liquid in Frameworks */ = {isa = PBXBuildFile; productRef = 89D99D2D2766FD6B00237814 /* Liquid */; };
|
||||
89F1386D2767EB19006680ED /* SignInView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89F1386C2767EB19006680ED /* SignInView.swift */; };
|
||||
89F138702767F55F006680ED /* GoogleSignIn in Frameworks */ = {isa = PBXBuildFile; productRef = 89F1386F2767F55F006680ED /* GoogleSignIn */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@@ -69,6 +70,7 @@
|
||||
89288EC7276756DF00E962C4 /* FirebaseDatabase in Frameworks */,
|
||||
89288EC9276756DF00E962C4 /* FirebaseStorage in Frameworks */,
|
||||
89D99D2E2766FD6B00237814 /* Liquid in Frameworks */,
|
||||
89F138702767F55F006680ED /* GoogleSignIn in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -229,6 +231,7 @@
|
||||
89288EC4276756DF00E962C4 /* FirebaseAuth */,
|
||||
89288EC6276756DF00E962C4 /* FirebaseDatabase */,
|
||||
89288EC8276756DF00E962C4 /* FirebaseStorage */,
|
||||
89F1386F2767F55F006680ED /* GoogleSignIn */,
|
||||
);
|
||||
productName = "nirvana-ios";
|
||||
productReference = 891A15DD27653A7000B26659 /* nirvana-ios.app */;
|
||||
@@ -261,6 +264,7 @@
|
||||
packageReferences = (
|
||||
89D99D2C2766FD6B00237814 /* XCRemoteSwiftPackageReference "liquid" */,
|
||||
89288EC1276756DF00E962C4 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
|
||||
89F1386E2767F55F006680ED /* XCRemoteSwiftPackageReference "GoogleSignIn-iOS" */,
|
||||
);
|
||||
productRefGroup = 891A15DE27653A7000B26659 /* Products */;
|
||||
projectDirPath = "";
|
||||
@@ -532,6 +536,14 @@
|
||||
minimumVersion = 0.0.2;
|
||||
};
|
||||
};
|
||||
89F1386E2767F55F006680ED /* XCRemoteSwiftPackageReference "GoogleSignIn-iOS" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/google/GoogleSignIn-iOS.git";
|
||||
requirement = {
|
||||
kind = upToNextMajorVersion;
|
||||
minimumVersion = 6.0.0;
|
||||
};
|
||||
};
|
||||
/* End XCRemoteSwiftPackageReference section */
|
||||
|
||||
/* Begin XCSwiftPackageProductDependency section */
|
||||
@@ -560,6 +572,11 @@
|
||||
package = 89D99D2C2766FD6B00237814 /* XCRemoteSwiftPackageReference "liquid" */;
|
||||
productName = Liquid;
|
||||
};
|
||||
89F1386F2767F55F006680ED /* GoogleSignIn */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 89F1386E2767F55F006680ED /* XCRemoteSwiftPackageReference "GoogleSignIn-iOS" */;
|
||||
productName = GoogleSignIn;
|
||||
};
|
||||
/* End XCSwiftPackageProductDependency section */
|
||||
};
|
||||
rootObject = 891A15D527653A7000B26659 /* Project object */;
|
||||
|
||||
@@ -10,6 +10,15 @@
|
||||
"version": "0.20200225.4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "AppAuth",
|
||||
"repositoryURL": "https://github.com/openid/AppAuth-iOS.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "01131d68346c8ae552961c768d583c715fbe1410",
|
||||
"version": "1.4.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "BoringSSL-GRPC",
|
||||
"repositoryURL": "https://github.com/firebase/boringssl-SwiftPM.git",
|
||||
@@ -46,6 +55,15 @@
|
||||
"version": "9.1.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "GoogleSignIn",
|
||||
"repositoryURL": "https://github.com/google/GoogleSignIn-iOS.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "27bc94f5e1bd1f3b12ba5abb2230dd77dd143f1e",
|
||||
"version": "6.0.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "GoogleUtilities",
|
||||
"repositoryURL": "https://github.com/google/GoogleUtilities.git",
|
||||
@@ -73,6 +91,15 @@
|
||||
"version": "1.7.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "GTMAppAuth",
|
||||
"repositoryURL": "https://github.com/google/GTMAppAuth.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "40f4103fb52109032c05599a0c39ad43edbdf80a",
|
||||
"version": "1.2.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "leveldb",
|
||||
"repositoryURL": "https://github.com/firebase/leveldb.git",
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "google.svg",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="48px" height="48px"><path fill="#fbc02d" d="M43.611,20.083H42V20H24v8h11.303c-1.649,4.657-6.08,8-11.303,8c-6.627,0-12-5.373-12-12 s5.373-12,12-12c3.059,0,5.842,1.154,7.961,3.039l5.657-5.657C34.046,6.053,29.268,4,24,4C12.955,4,4,12.955,4,24s8.955,20,20,20 s20-8.955,20-20C44,22.659,43.862,21.35,43.611,20.083z"/><path fill="#e53935" d="M6.306,14.691l6.571,4.819C14.655,15.108,18.961,12,24,12c3.059,0,5.842,1.154,7.961,3.039 l5.657-5.657C34.046,6.053,29.268,4,24,4C16.318,4,9.656,8.337,6.306,14.691z"/><path fill="#4caf50" d="M24,44c5.166,0,9.86-1.977,13.409-5.192l-6.19-5.238C29.211,35.091,26.715,36,24,36 c-5.202,0-9.619-3.317-11.283-7.946l-6.522,5.025C9.505,39.556,16.227,44,24,44z"/><path fill="#1565c0" d="M43.611,20.083L43.595,20L42,20H24v8h11.303c-0.792,2.237-2.231,4.166-4.087,5.571 c0.001-0.001,0.002-0.001,0.003-0.002l6.19,5.238C36.971,39.205,44,34,44,24C44,22.659,43.862,21.35,43.611,20.083z"/></svg>
|
||||
|
After Width: | Height: | Size: 977 B |
@@ -2,6 +2,17 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>com.googleusercontent.apps.93806270104-62r53m53imapfocl1sck8bn4ho910ndh</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>UIAppFonts</key>
|
||||
<array>
|
||||
<string>Satisfy-Regular.ttf</string>
|
||||
|
||||
@@ -6,38 +6,101 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Firebase
|
||||
import AuthenticationServices
|
||||
import GoogleSignIn
|
||||
|
||||
struct SignInView: View {
|
||||
var body: some View {
|
||||
OnboardingTemplateView(hdrText: "Let's get started", imgName: "undraw_enter_uhqk", bottomActArea:
|
||||
AnyView(
|
||||
VStack(alignment: .center) {
|
||||
NavigationLink(destination: HomeView()) {
|
||||
Text("Sign Up")
|
||||
.bold()
|
||||
.foregroundColor(NirvanaColor.white)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 20)
|
||||
.background(NirvanaColor.teal)
|
||||
.clipShape(Capsule())
|
||||
.shadow(radius:10)
|
||||
}
|
||||
|
||||
Button(
|
||||
action: {
|
||||
print("link to website learn more clicked")
|
||||
},
|
||||
label: {
|
||||
Text("Learn More")
|
||||
// SignInWithAppleButton(.signIn,
|
||||
// onRequest: { request in
|
||||
// print("siginin in ")
|
||||
// }, onCompletion: {result in
|
||||
// print("signed in")
|
||||
// })
|
||||
// .frame(height:50)
|
||||
// .clipShape(Capsule())
|
||||
// .shadow(radius:20)
|
||||
|
||||
Button {
|
||||
self.handleLogin()
|
||||
} label: {
|
||||
HStack {
|
||||
Image("google")
|
||||
.resizable()
|
||||
.renderingMode(.template)
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 28, height: 28)
|
||||
.foregroundColor(NirvanaColor.white)
|
||||
|
||||
Text("Continue with Google")
|
||||
.foregroundColor(NirvanaColor.white)
|
||||
.bold()
|
||||
})
|
||||
|
||||
//learn more button to usenirvana.com
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 20)
|
||||
.background(NirvanaColor.teal)
|
||||
.clipShape(Capsule())
|
||||
.shadow(radius:10)
|
||||
}
|
||||
|
||||
|
||||
Text("By continuing, you are agreeing to our Terms of Service.")
|
||||
.font(.callout.bold())
|
||||
.foregroundColor(.gray)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
}
|
||||
.padding(.top, 20)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
func handleLogin(){
|
||||
//Google sign in
|
||||
guard let clientID = FirebaseApp.app()?.options.clientID else { return }
|
||||
|
||||
// create google sign in configuration object
|
||||
let config = GIDConfiguration(clientID: clientID)
|
||||
|
||||
GIDSignIn.sharedInstance.signIn(with: config, presenting: getRootViewController())
|
||||
{[self] user, err in
|
||||
|
||||
if let error = err {
|
||||
print(err)
|
||||
return
|
||||
}
|
||||
|
||||
guard
|
||||
let authentication = user?.authentication,
|
||||
let idToken = authentication.idToken
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
let credential = GoogleAuthProvider.credential(withIDToken: idToken,
|
||||
accessToken: authentication.accessToken)
|
||||
|
||||
Auth.auth().signIn(with: credential) { result, error in
|
||||
if let error = error {
|
||||
print(error.localizedDescription)
|
||||
}
|
||||
|
||||
guard let user = result?.user else {
|
||||
return
|
||||
}
|
||||
|
||||
print(user.displayName ?? "Success!")
|
||||
print(user.photoURL)
|
||||
// User is signed in
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct SignInView_Previews: PreviewProvider {
|
||||
@@ -45,3 +108,15 @@ struct SignInView_Previews: PreviewProvider {
|
||||
SignInView()
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
func getRootViewController() -> UIViewController {
|
||||
guard let screen = UIApplication.shared.connectedScenes.first as? UIWindowScene else { return .init() }
|
||||
|
||||
guard let root = screen.windows.first?.rootViewController else {
|
||||
return .init()
|
||||
}
|
||||
|
||||
return root
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ struct OnboardingTemplateView: View {
|
||||
HeaderView()
|
||||
|
||||
VStack {
|
||||
self.onboardingHeaderText
|
||||
|
||||
self.onboardingImageView
|
||||
|
||||
self.onboardingActionTextView
|
||||
@@ -51,7 +53,7 @@ struct OnboardingTemplateView: View {
|
||||
|
||||
self.bottomActionArea
|
||||
}
|
||||
.padding(screenWidth * 0.1)
|
||||
.padding(.horizontal, screenWidth * 0.1)
|
||||
|
||||
Spacer()
|
||||
} //outermost vstack
|
||||
@@ -60,6 +62,19 @@ struct OnboardingTemplateView: View {
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
}
|
||||
|
||||
private var onboardingHeaderText: some View {
|
||||
ZStack {
|
||||
if (self.headerText != nil) {
|
||||
Text(self.headerText!)
|
||||
.font(.title)
|
||||
.fontWeight(.medium)
|
||||
.foregroundColor(NirvanaColor.teal)
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
private var onboardingImageView: some View {
|
||||
Image(self.imageName ?? "")
|
||||
.renderingMode(.original)
|
||||
@@ -98,7 +113,7 @@ struct OnboardingTemplateView: View {
|
||||
|
||||
struct OnboardingTemplateView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
OnboardingTemplateView(imgName: "undraw_friendship_mni7", mainLeadingActText: "Your", mainHighlightedActText: "minimalist", mainTrailingActText: "social media.", subActText: "Tired of the rat race on the test of th4e best oadf the best?", bottomActArea: AnyView(
|
||||
OnboardingTemplateView(hdrText: "let's get started", imgName: "undraw_friendship_mni7", mainLeadingActText: "Your", mainHighlightedActText: "minimalist", mainTrailingActText: "social media.", subActText: "Tired of the rat race on the test of th4e best oadf the best?", bottomActArea: AnyView(
|
||||
VStack(alignment: .center) {
|
||||
NavigationLink(destination: HomeView()) {
|
||||
Text("Start Your Detox")
|
||||
|
||||
@@ -14,7 +14,7 @@ struct WelcomeView: View {
|
||||
var body: some View {
|
||||
OnboardingTemplateView(imgName: "undraw_friendship_mni7", mainLeadingActText: "Your", mainHighlightedActText: "minimalist", mainTrailingActText: "social media.", subActText: "Tired of the rat race on insta, snap, tik-tok, \"meta\"?", bottomActArea: AnyView(
|
||||
VStack(alignment: .center) {
|
||||
NavigationLink(destination: HomeView()) {
|
||||
NavigationLink(destination: SignInView()) {
|
||||
Text("Start Your Detox")
|
||||
.bold()
|
||||
.foregroundColor(NirvanaColor.white)
|
||||
|
||||
@@ -7,17 +7,27 @@
|
||||
|
||||
import SwiftUI
|
||||
import Firebase
|
||||
import GoogleSignIn
|
||||
|
||||
@main
|
||||
struct nirvana_iosApp: App {
|
||||
|
||||
init() {
|
||||
FirebaseApp.configure()
|
||||
}
|
||||
|
||||
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ContentView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AppDelegate: NSObject, UIApplicationDelegate{
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
|
||||
[UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
||||
FirebaseApp.configure()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
|
||||
return GIDSignIn.sharedInstance.handle(url)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user