-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add userIdentities method * Update dependencies * wip * fix corrupted Package.resolved * wip * Fix typo * Add example for unlink identity * test: add snapshot test to unlinkIdentity method * Fix unlink identity and add example * fix examples build * Hide add button when unsupported
- Loading branch information
Showing
15 changed files
with
497 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// AnyJSONView.swift | ||
// Examples | ||
// | ||
// Created by Guilherme Souza on 21/03/24. | ||
// | ||
|
||
import Supabase | ||
import SwiftUI | ||
|
||
struct AnyJSONView: View { | ||
let value: AnyJSON | ||
|
||
var body: some View { | ||
switch value { | ||
case .null: Text("<nil>") | ||
case let .bool(value): Text(value.description) | ||
case let .double(value): Text(value.description) | ||
case let .integer(value): Text(value.description) | ||
case let .string(value): Text(value) | ||
case let .array(value): | ||
ForEach(0 ..< value.count, id: \.self) { index in | ||
if value[index].isPrimitive { | ||
LabeledContent("\(index)") { | ||
AnyJSONView(value: value[index]) | ||
} | ||
} else { | ||
NavigationLink("\(index)") { | ||
List { | ||
AnyJSONView(value: value[index]) | ||
} | ||
.navigationTitle("\(index)") | ||
} | ||
} | ||
} | ||
|
||
case let .object(object): | ||
let elements = Array(object).sorted(by: { $0.key < $1.key }) | ||
ForEach(elements, id: \.key) { element in | ||
if element.value.isPrimitive { | ||
LabeledContent(element.key) { | ||
AnyJSONView(value: element.value) | ||
} | ||
} else { | ||
NavigationLink(element.key) { | ||
List { | ||
AnyJSONView(value: element.value) | ||
} | ||
.navigationTitle(element.key) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
extension AnyJSON { | ||
var isPrimitive: Bool { | ||
switch self { | ||
case .null, .bool, .integer, .double, .string: | ||
return true | ||
case .object, .array: | ||
return false | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
NavigationStack { | ||
AnyJSONView( | ||
value: [ | ||
"app_metadata": [ | ||
"provider": "email", | ||
"providers": [ | ||
"email", | ||
], | ||
], | ||
"aud": "authenticated", | ||
"confirmed_at": "2024-03-21T03:19:10.147869Z", | ||
"created_at": "2024-03-21T03:19:10.142559Z", | ||
"email": "[email protected]", | ||
"email_confirmed_at": "2024-03-21T03:19:10.147869Z", | ||
"id": "06f83324-e553-4d39-a609-fd30682ee127", | ||
"identities": [ | ||
[ | ||
"created_at": "2024-03-21T03:19:10.146262Z", | ||
"email": "[email protected]", | ||
"id": "06f83324-e553-4d39-a609-fd30682ee127", | ||
"identity_data": [ | ||
"email": "[email protected]", | ||
"email_verified": false, | ||
"phone_verified": false, | ||
"sub": "06f83324-e553-4d39-a609-fd30682ee127", | ||
], | ||
"identity_id": "35aafcdf-f12e-4e3d-8302-63ff587c041c", | ||
"last_sign_in_at": "2024-03-21T03:19:10.146245Z", | ||
"provider": "email", | ||
"updated_at": "2024-03-21T03:19:10.146262Z", | ||
"user_id": "06f83324-e553-4d39-a609-fd30682ee127", | ||
], | ||
], | ||
"last_sign_in_at": "2024-03-21T03:19:10.149557Z", | ||
"phone": "", | ||
"role": "authenticated", | ||
"updated_at": "2024-03-21T05:37:40.596682Z", | ||
] | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// ProfileView.swift | ||
// Examples | ||
// | ||
// Created by Guilherme Souza on 21/03/24. | ||
// | ||
|
||
import Supabase | ||
import SwiftUI | ||
|
||
struct ProfileView: View { | ||
@State var user: User? | ||
|
||
var identities: [UserIdentity] { | ||
user?.identities ?? [] | ||
} | ||
|
||
var body: some View { | ||
NavigationStack { | ||
List { | ||
if let user = user.flatMap({ try? AnyJSON($0) }) { | ||
Section { | ||
AnyJSONView(value: user) | ||
} | ||
} | ||
|
||
NavigationLink("Identities") { | ||
UserIdentityList() | ||
.navigationTitle("Identities") | ||
} | ||
|
||
Button("Reauthenticate") { | ||
Task { | ||
try! await supabase.auth.reauthenticate() | ||
} | ||
} | ||
|
||
Menu("Unlink identity") { | ||
ForEach(identities) { identity in | ||
Button(identity.provider) { | ||
Task { | ||
do { | ||
try await supabase.auth.unlinkIdentity(identity) | ||
} catch { | ||
debug("Fail to unlink identity: \(error)") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
Button("Sign out", role: .destructive) { | ||
Task { | ||
try! await supabase.auth.signOut() | ||
} | ||
} | ||
} | ||
.navigationTitle("Profile") | ||
} | ||
.task { | ||
do { | ||
user = try await supabase.auth.user() | ||
} catch { | ||
debug("Fail to fetch user: \(error)") | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
ProfileView() | ||
} |
Oops, something went wrong.