Skip to content

Commit fca6721

Browse files
authored
feat: add reauthenticate method (#271)
1 parent b6a1b0b commit fca6721

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

Examples/Examples/HomeView.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ struct HomeView: View {
1515
var body: some View {
1616
TodoListView()
1717
.toolbar {
18-
ToolbarItem(placement: .cancellationAction) {
18+
ToolbarItemGroup(placement: .cancellationAction) {
1919
Button("Sign out") {
2020
Task {
2121
try! await supabase.auth.signOut()
2222
}
2323
}
24+
25+
Button("Reauthenticate") {
26+
Task {
27+
try! await supabase.auth.reauthenticate()
28+
}
29+
}
2430
}
2531
}
2632
.task {

Sources/Auth/AuthClient.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,13 @@ public actor AuthClient {
811811
.decoded(decoder: configuration.decoder)
812812
}
813813

814+
/// Sends a re-authentication OTP to the user's email or phone number.
815+
public func reauthenticate() async throws {
816+
try await api.authorizedExecute(
817+
Request(path: "/reauthenticate", method: .get)
818+
)
819+
}
820+
814821
/// Gets the current user details if there is an existing session.
815822
/// - Parameter jwt: Takes in an optional access token jwt. If no jwt is provided, user() will
816823
/// attempt to get the jwt from the current session.

Tests/AuthTests/RequestsTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,16 @@ final class RequestsTests: XCTestCase {
344344
}
345345
}
346346

347+
func testReauthenticate() async {
348+
sessionManager.returnSession = .success(.validSession)
349+
350+
let sut = makeSUT()
351+
352+
await assert {
353+
try await sut.reauthenticate()
354+
}
355+
}
356+
347357
private func assert(_ block: () async throws -> Void) async {
348358
do {
349359
try await block()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
curl \
2+
--header "Apikey: dummy.api.key" \
3+
--header "Authorization: Bearer accesstoken" \
4+
--header "X-Client-Info: gotrue-swift/x.y.z" \
5+
"http://localhost:54321/auth/v1/reauthenticate"

Tests/RealtimeTests/_PushTests.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by Guilherme Souza on 03/01/24.
66
//
77

8+
import ConcurrencyExtras
89
@testable import Realtime
910
import XCTest
1011

@@ -14,6 +15,12 @@ final class _PushTests: XCTestCase {
1415
apiKey: "apikey"
1516
))
1617

18+
override func invokeTest() {
19+
withMainSerialExecutor {
20+
super.invokeTest()
21+
}
22+
}
23+
1724
func testPushWithoutAck() async {
1825
let channel = RealtimeChannelV2(
1926
topic: "realtime:users",
@@ -64,7 +71,6 @@ final class _PushTests: XCTestCase {
6471
await push.send()
6572
}
6673
await Task.megaYield()
67-
6874
await push.didReceive(status: .ok)
6975

7076
let status = await task.value

supabase-swift.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)