Skip to content

Commit

Permalink
feat: add reauthenticate method (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Mar 19, 2024
1 parent b6a1b0b commit fca6721
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
8 changes: 7 additions & 1 deletion Examples/Examples/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ struct HomeView: View {
var body: some View {
TodoListView()
.toolbar {
ToolbarItem(placement: .cancellationAction) {
ToolbarItemGroup(placement: .cancellationAction) {
Button("Sign out") {
Task {
try! await supabase.auth.signOut()
}
}

Button("Reauthenticate") {
Task {
try! await supabase.auth.reauthenticate()
}
}
}
}
.task {
Expand Down
7 changes: 7 additions & 0 deletions Sources/Auth/AuthClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,13 @@ public actor AuthClient {
.decoded(decoder: configuration.decoder)
}

/// Sends a re-authentication OTP to the user's email or phone number.
public func reauthenticate() async throws {
try await api.authorizedExecute(
Request(path: "/reauthenticate", method: .get)
)
}

/// Gets the current user details if there is an existing session.
/// - Parameter jwt: Takes in an optional access token jwt. If no jwt is provided, user() will
/// attempt to get the jwt from the current session.
Expand Down
10 changes: 10 additions & 0 deletions Tests/AuthTests/RequestsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ final class RequestsTests: XCTestCase {
}
}

func testReauthenticate() async {
sessionManager.returnSession = .success(.validSession)

let sut = makeSUT()

await assert {
try await sut.reauthenticate()
}
}

private func assert(_ block: () async throws -> Void) async {
do {
try await block()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
curl \
--header "Apikey: dummy.api.key" \
--header "Authorization: Bearer accesstoken" \
--header "X-Client-Info: gotrue-swift/x.y.z" \
"http://localhost:54321/auth/v1/reauthenticate"
8 changes: 7 additions & 1 deletion Tests/RealtimeTests/_PushTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Guilherme Souza on 03/01/24.
//

import ConcurrencyExtras
@testable import Realtime
import XCTest

Expand All @@ -14,6 +15,12 @@ final class _PushTests: XCTestCase {
apiKey: "apikey"
))

override func invokeTest() {
withMainSerialExecutor {
super.invokeTest()
}
}

func testPushWithoutAck() async {
let channel = RealtimeChannelV2(
topic: "realtime:users",
Expand Down Expand Up @@ -64,7 +71,6 @@ final class _PushTests: XCTestCase {
await push.send()
}
await Task.megaYield()

await push.didReceive(status: .ok)

let status = await task.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/openid/AppAuth-iOS.git",
"state" : {
"revision" : "269c90515328c24f90b2ed17a67c8a796b485448",
"version" : "1.7.2"
"revision" : "7e2c09cbeb3bb799f26c268dbedb26325ea722a9",
"version" : "1.7.3"
}
},
{
Expand Down Expand Up @@ -95,8 +95,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "3ce83179e5f0c83ad54c305779c6b438e82aaf1d",
"version" : "1.2.1"
"revision" : "f01efb26f3a192a0e88dcdb7c3c391ec2fc25d9c",
"version" : "1.3.0"
}
},
{
Expand Down

0 comments on commit fca6721

Please sign in to comment.