mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 18:28:25 +08:00
feat: add read-only support to authentication fields
This commit is contained in:
@@ -7,12 +7,14 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
class ApiKeyAuthFields extends StatefulWidget {
|
class ApiKeyAuthFields extends StatefulWidget {
|
||||||
final AuthModel? authData;
|
final AuthModel? authData;
|
||||||
|
final bool readOnly;
|
||||||
final Function(AuthModel?) updateAuth;
|
final Function(AuthModel?) updateAuth;
|
||||||
|
|
||||||
const ApiKeyAuthFields({
|
const ApiKeyAuthFields({
|
||||||
super.key,
|
super.key,
|
||||||
required this.authData,
|
required this.authData,
|
||||||
required this.updateAuth,
|
required this.updateAuth,
|
||||||
|
this.readOnly = false
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -67,12 +69,14 @@ class _ApiKeyAuthFieldsState extends State<ApiKeyAuthFields> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
|
readOnly: widget.readOnly,
|
||||||
controller: _nameController,
|
controller: _nameController,
|
||||||
hintText: "Header/Query Param Name",
|
hintText: "Header/Query Param Name",
|
||||||
onChanged: (value) => _updateApiKeyAuth(),
|
onChanged: (value) => _updateApiKeyAuth(),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
|
readOnly: widget.readOnly,
|
||||||
controller: _keyController,
|
controller: _keyController,
|
||||||
hintText: "API Key",
|
hintText: "API Key",
|
||||||
isObscureText: true,
|
isObscureText: true,
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ import 'package:apidash_core/apidash_core.dart';
|
|||||||
class BasicAuthFields extends StatelessWidget {
|
class BasicAuthFields extends StatelessWidget {
|
||||||
final AuthModel? authData;
|
final AuthModel? authData;
|
||||||
final Function(AuthModel?) updateAuth;
|
final Function(AuthModel?) updateAuth;
|
||||||
|
final bool readOnly;
|
||||||
|
|
||||||
const BasicAuthFields({
|
const BasicAuthFields({
|
||||||
super.key,
|
super.key,
|
||||||
required this.authData,
|
required this.authData,
|
||||||
required this.updateAuth,
|
required this.updateAuth,
|
||||||
|
this.readOnly = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -25,6 +27,7 @@ class BasicAuthFields extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
|
readOnly: readOnly,
|
||||||
hintText: "Username",
|
hintText: "Username",
|
||||||
controller: usernameController,
|
controller: usernameController,
|
||||||
onChanged: (_) => _updateBasicAuth(
|
onChanged: (_) => _updateBasicAuth(
|
||||||
@@ -34,6 +37,7 @@ class BasicAuthFields extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
|
readOnly: readOnly,
|
||||||
hintText: "Password",
|
hintText: "Password",
|
||||||
isObscureText: true,
|
isObscureText: true,
|
||||||
controller: passwordController,
|
controller: passwordController,
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ import 'package:flutter/material.dart';
|
|||||||
class BearerAuthFields extends StatefulWidget {
|
class BearerAuthFields extends StatefulWidget {
|
||||||
final AuthModel? authData;
|
final AuthModel? authData;
|
||||||
final Function(AuthModel?) updateAuth;
|
final Function(AuthModel?) updateAuth;
|
||||||
|
final bool readOnly;
|
||||||
|
|
||||||
const BearerAuthFields({
|
const BearerAuthFields({
|
||||||
super.key,
|
super.key,
|
||||||
required this.authData,
|
required this.authData,
|
||||||
required this.updateAuth,
|
required this.updateAuth,
|
||||||
|
this.readOnly = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -29,6 +31,7 @@ class _BearerAuthFieldsState extends State<BearerAuthFields> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return AuthTextField(
|
return AuthTextField(
|
||||||
|
readOnly: widget.readOnly,
|
||||||
controller: _tokenController,
|
controller: _tokenController,
|
||||||
hintText: "Token",
|
hintText: "Token",
|
||||||
isObscureText: true,
|
isObscureText: true,
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ import 'package:apidash_core/apidash_core.dart';
|
|||||||
class JwtAuthFields extends StatefulWidget {
|
class JwtAuthFields extends StatefulWidget {
|
||||||
final AuthModel? authData;
|
final AuthModel? authData;
|
||||||
final Function(AuthModel?) updateAuth;
|
final Function(AuthModel?) updateAuth;
|
||||||
|
final bool readOnly;
|
||||||
|
|
||||||
const JwtAuthFields({
|
const JwtAuthFields({
|
||||||
super.key,
|
super.key,
|
||||||
required this.authData,
|
required this.authData,
|
||||||
required this.updateAuth,
|
required this.updateAuth,
|
||||||
|
this.readOnly = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -95,6 +97,7 @@ class _JwtAuthFieldsState extends State<JwtAuthFields> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
|
readOnly: widget.readOnly,
|
||||||
controller: _secretController,
|
controller: _secretController,
|
||||||
isObscureText: true,
|
isObscureText: true,
|
||||||
hintText: "Secret key",
|
hintText: "Secret key",
|
||||||
@@ -130,6 +133,7 @@ class _JwtAuthFieldsState extends State<JwtAuthFields> {
|
|||||||
),
|
),
|
||||||
SizedBox(height: 4),
|
SizedBox(height: 4),
|
||||||
TextField(
|
TextField(
|
||||||
|
readOnly: widget.readOnly,
|
||||||
controller: _payloadController,
|
controller: _payloadController,
|
||||||
maxLines: 4,
|
maxLines: 4,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ class AuthTextField extends StatefulWidget {
|
|||||||
final TextEditingController controller;
|
final TextEditingController controller;
|
||||||
final bool isObscureText;
|
final bool isObscureText;
|
||||||
final Function(String)? onChanged;
|
final Function(String)? onChanged;
|
||||||
|
final bool readOnly;
|
||||||
|
|
||||||
const AuthTextField({
|
const AuthTextField({
|
||||||
super.key,
|
super.key,
|
||||||
required this.hintText,
|
required this.hintText,
|
||||||
required this.controller,
|
required this.controller,
|
||||||
required this.onChanged,
|
required this.onChanged,
|
||||||
|
this.readOnly = false,
|
||||||
this.isObscureText = false,
|
this.isObscureText = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -51,6 +53,7 @@ class _AuthFieldState extends State<AuthTextField> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 6),
|
const SizedBox(height: 6),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
readOnly: widget.readOnly,
|
||||||
controller: widget.controller,
|
controller: widget.controller,
|
||||||
style: kCodeStyle.copyWith(
|
style: kCodeStyle.copyWith(
|
||||||
color: Theme.of(context).colorScheme.onSurface,
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:apidash/screens/common_widgets/auth/api_key_auth_fields.dart';
|
import 'package:apidash/screens/common_widgets/auth/api_key_auth_fields.dart';
|
||||||
import 'package:apidash/screens/common_widgets/auth/basic_auth_fields.dart';
|
import 'package:apidash/screens/common_widgets/auth/basic_auth_fields.dart';
|
||||||
import 'package:apidash/screens/common_widgets/auth/bearer_auth_fields.dart';
|
import 'package:apidash/screens/common_widgets/auth/bearer_auth_fields.dart';
|
||||||
@@ -24,17 +26,19 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
final APIAuthType currentAuthType;
|
final APIAuthType currentAuthType;
|
||||||
|
|
||||||
if (authModel != null) {
|
if (authModel != null) {
|
||||||
|
log("Got Auth Model");
|
||||||
currentAuthData = authModel;
|
currentAuthData = authModel;
|
||||||
currentAuthType = authModel!.type;
|
currentAuthType = authModel!.type;
|
||||||
} else {
|
} else {
|
||||||
|
log("Using Provider");
|
||||||
final selectedRequest = ref.read(selectedRequestModelProvider);
|
final selectedRequest = ref.read(selectedRequestModelProvider);
|
||||||
if (selectedRequest == null) {
|
if (selectedRequest == null) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
|
||||||
currentAuthType = ref.watch(
|
currentAuthType = ref.watch(
|
||||||
selectedRequestModelProvider.select((request) =>
|
selectedRequestModelProvider
|
||||||
request?.authModel?.type ?? APIAuthType.none),
|
.select((request) => request?.authModel?.type ?? APIAuthType.none),
|
||||||
);
|
);
|
||||||
currentAuthData = selectedRequest.authModel;
|
currentAuthData = selectedRequest.authModel;
|
||||||
}
|
}
|
||||||
@@ -115,6 +119,11 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
AuthModel? authData,
|
AuthModel? authData,
|
||||||
) {
|
) {
|
||||||
void updateAuth(AuthModel? model) {
|
void updateAuth(AuthModel? model) {
|
||||||
|
if (model == null) {
|
||||||
|
ref.read(collectionStateNotifierProvider.notifier).update(
|
||||||
|
authData: AuthModel(type: APIAuthType.none),
|
||||||
|
);
|
||||||
|
}
|
||||||
ref.read(collectionStateNotifierProvider.notifier).update(
|
ref.read(collectionStateNotifierProvider.notifier).update(
|
||||||
authData: model,
|
authData: model,
|
||||||
);
|
);
|
||||||
@@ -123,21 +132,25 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
switch (authData?.type) {
|
switch (authData?.type) {
|
||||||
case APIAuthType.basic:
|
case APIAuthType.basic:
|
||||||
return BasicAuthFields(
|
return BasicAuthFields(
|
||||||
|
readOnly: readOnly,
|
||||||
authData: authData,
|
authData: authData,
|
||||||
updateAuth: updateAuth,
|
updateAuth: updateAuth,
|
||||||
);
|
);
|
||||||
case APIAuthType.bearer:
|
case APIAuthType.bearer:
|
||||||
return BearerAuthFields(
|
return BearerAuthFields(
|
||||||
|
readOnly: readOnly,
|
||||||
authData: authData,
|
authData: authData,
|
||||||
updateAuth: updateAuth,
|
updateAuth: updateAuth,
|
||||||
);
|
);
|
||||||
case APIAuthType.apiKey:
|
case APIAuthType.apiKey:
|
||||||
return ApiKeyAuthFields(
|
return ApiKeyAuthFields(
|
||||||
|
readOnly: readOnly,
|
||||||
authData: authData,
|
authData: authData,
|
||||||
updateAuth: updateAuth,
|
updateAuth: updateAuth,
|
||||||
);
|
);
|
||||||
case APIAuthType.jwt:
|
case APIAuthType.jwt:
|
||||||
return JwtAuthFields(
|
return JwtAuthFields(
|
||||||
|
readOnly: readOnly,
|
||||||
authData: authData,
|
authData: authData,
|
||||||
updateAuth: updateAuth,
|
updateAuth: updateAuth,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user