Skip to content

Commit def1d75

Browse files
author
Guilherme Souza
committed
wip example project refactor
1 parent 5aeb803 commit def1d75

File tree

14 files changed

+71
-50
lines changed

14 files changed

+71
-50
lines changed

.swiftpm/xcode/xcshareddata/xcschemes/Functions.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1500"
3+
LastUpgradeVersion = "1510"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"

.swiftpm/xcode/xcshareddata/xcschemes/PostgREST.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1500"
3+
LastUpgradeVersion = "1510"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"

.swiftpm/xcode/xcshareddata/xcschemes/Realtime.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1500"
3+
LastUpgradeVersion = "1510"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"

.swiftpm/xcode/xcshareddata/xcschemes/Storage.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1500"
3+
LastUpgradeVersion = "1510"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"

.swiftpm/xcode/xcshareddata/xcschemes/Supabase.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1500"
3+
LastUpgradeVersion = "1510"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"

Examples/Examples.xcodeproj/project.pbxproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@
290290
attributes = {
291291
BuildIndependentTargetsInParallel = 1;
292292
LastSwiftUpdateCheck = 1500;
293-
LastUpgradeCheck = 1500;
293+
LastUpgradeCheck = 1510;
294294
TargetAttributes = {
295295
790308E52AEE7B4D003C4A98 = {
296296
CreatedOnToolsVersion = 15.0.1;
@@ -425,7 +425,6 @@
425425
"@executable_path/../Frameworks",
426426
);
427427
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
428-
MACOSX_DEPLOYMENT_TARGET = 14.0;
429428
MARKETING_VERSION = 1.0;
430429
PRODUCT_BUNDLE_IDENTIFIER = dev.grds.RealtimeSample;
431430
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -460,7 +459,6 @@
460459
"@executable_path/../Frameworks",
461460
);
462461
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
463-
MACOSX_DEPLOYMENT_TARGET = 14.0;
464462
MARKETING_VERSION = 1.0;
465463
PRODUCT_BUNDLE_IDENTIFIER = dev.grds.RealtimeSample;
466464
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -477,6 +475,7 @@
477475
isa = XCBuildConfiguration;
478476
buildSettings = {
479477
ALWAYS_SEARCH_USER_PATHS = NO;
478+
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
480479
CLANG_ANALYZER_NONNULL = YES;
481480
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
482481
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
@@ -527,11 +526,12 @@
527526
GCC_WARN_UNUSED_FUNCTION = YES;
528527
GCC_WARN_UNUSED_VARIABLE = YES;
529528
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
530-
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
529+
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
531530
LD_RUNPATH_SEARCH_PATHS = (
532531
"$(inherited)",
533532
"@executable_path/Frameworks",
534533
);
534+
MACOSX_DEPLOYMENT_TARGET = 14.0;
535535
MARKETING_VERSION = 1.0.0;
536536
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
537537
MTL_FAST_MATH = YES;
@@ -548,6 +548,7 @@
548548
isa = XCBuildConfiguration;
549549
buildSettings = {
550550
ALWAYS_SEARCH_USER_PATHS = NO;
551+
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
551552
CLANG_ANALYZER_NONNULL = YES;
552553
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
553554
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
@@ -592,11 +593,12 @@
592593
GCC_WARN_UNUSED_FUNCTION = YES;
593594
GCC_WARN_UNUSED_VARIABLE = YES;
594595
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
595-
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
596+
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
596597
LD_RUNPATH_SEARCH_PATHS = (
597598
"$(inherited)",
598599
"@executable_path/Frameworks",
599600
);
601+
MACOSX_DEPLOYMENT_TARGET = 14.0;
600602
MARKETING_VERSION = 1.0.0;
601603
MTL_ENABLE_DEBUG_INFO = NO;
602604
MTL_FAST_MATH = YES;
@@ -677,7 +679,6 @@
677679
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
678680
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
679681
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
680-
MACOSX_DEPLOYMENT_TARGET = 14.0;
681682
MARKETING_VERSION = 1.0;
682683
PRODUCT_BUNDLE_IDENTIFIER = com.supabase.UserManagement;
683684
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -719,7 +720,6 @@
719720
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
720721
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
721722
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
722-
MACOSX_DEPLOYMENT_TARGET = 14.0;
723723
MARKETING_VERSION = 1.0;
724724
PRODUCT_BUNDLE_IDENTIFIER = com.supabase.UserManagement;
725725
PRODUCT_NAME = "$(TARGET_NAME)";

Examples/Examples.xcodeproj/xcshareddata/xcschemes/Examples.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1500"
3+
LastUpgradeVersion = "1510"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"

Examples/Examples/AuthView.swift

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
// Created by Guilherme Souza on 22/12/22.
66
//
77

8-
import GoTrue
8+
import Auth
99
import SwiftUI
1010

11+
@Observable
1112
@MainActor
12-
final class AuthController: ObservableObject {
13-
@Published var session: Session?
13+
final class AuthController {
14+
var session: Session?
1415

1516
var currentUserID: UUID {
1617
guard let id = session?.user.id else {
@@ -20,28 +21,42 @@ final class AuthController: ObservableObject {
2021
return id
2122
}
2223

23-
func observeAuth() async {
24-
for await (event, session) in await supabase.auth.onAuthStateChange() {
25-
guard event == .signedIn || event == .signedOut else {
26-
return
27-
}
24+
@ObservationIgnored
25+
private var observeAuthStateChangesTask: Task<Void, Never>?
26+
27+
init() {
28+
observeAuthStateChangesTask = Task {
29+
for await (event, session) in await supabase.auth.authStateChanges {
30+
guard event == .initialSession || event == .signedIn || event == .signedOut else {
31+
return
32+
}
2833

29-
self.session = session
34+
self.session = session
35+
}
3036
}
3137
}
38+
39+
deinit {
40+
observeAuthStateChangesTask?.cancel()
41+
}
3242
}
3343

3444
struct AuthView: View {
3545
enum Mode {
3646
case signIn, signUp
3747
}
3848

39-
@EnvironmentObject var auth: AuthController
49+
@Environment(AuthController.self) var auth
4050

4151
@State var email = ""
4252
@State var password = ""
4353
@State var mode: Mode = .signIn
44-
@State var error: Error?
54+
@State var result: Result?
55+
56+
enum Result {
57+
case failure(Error)
58+
case needsEmailConfirmation
59+
}
4560

4661
var body: some View {
4762
Form {
@@ -61,9 +76,13 @@ struct AuthView: View {
6176
}
6277
}
6378

64-
if let error {
79+
if case .failure(let error) = result {
6580
ErrorText(error)
6681
}
82+
83+
if case .needsEmailConfirmation = result {
84+
Text("Check you inbox.")
85+
}
6786
}
6887

6988
Section {
@@ -72,26 +91,33 @@ struct AuthView: View {
7291
) {
7392
withAnimation {
7493
mode = mode == .signIn ? .signUp : .signIn
94+
result = nil
7595
}
7696
}
7797
}
7898
}
99+
.navigationTitle("Auth with Email & Password")
100+
.navigationBarTitleDisplayMode(.inline)
79101
}
80102

81103
func primaryActionButtonTapped() async {
82104
do {
83-
error = nil
105+
result = nil
84106
switch mode {
85107
case .signIn:
86108
try await supabase.auth.signIn(email: email, password: password)
87109
case .signUp:
88-
try await supabase.auth.signUp(
110+
let response = try await supabase.auth.signUp(
89111
email: email, password: password, redirectTo: URL(string: "com.supabase.Examples://")!
90112
)
113+
114+
if case .user = response {
115+
result = .needsEmailConfirmation
116+
}
91117
}
92118
} catch {
93119
withAnimation {
94-
self.error = error
120+
result = .failure(error)
95121
}
96122
}
97123
}

Examples/Examples/ErrorText.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct ErrorText: View {
1515
}
1616

1717
var body: some View {
18-
Text(String(describing: error))
18+
Text(error.localizedDescription)
1919
.foregroundColor(.red)
2020
.font(.footnote)
2121
}

Examples/Examples/ExamplesApp.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import SwiftUI
1010

1111
@main
1212
struct ExamplesApp: App {
13-
@StateObject var auth = AuthController()
14-
1513
var body: some Scene {
1614
WindowGroup {
1715
RootView()
18-
.environmentObject(auth)
16+
.environment(AuthController())
1917
}
2018
}
2119
}

0 commit comments

Comments
 (0)