Skip to content

feat: add reauthenticate method #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.