@rigstate/mcp 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/supabase.ts +9 -13
package/dist/index.js
CHANGED
|
@@ -1074,20 +1074,21 @@ async function authenticateApiKey(apiKey) {
|
|
|
1074
1074
|
error: "Supabase configuration missing. Set RIGSTATE_SUPABASE_URL and RIGSTATE_SUPABASE_ANON_KEY."
|
|
1075
1075
|
};
|
|
1076
1076
|
}
|
|
1077
|
-
const
|
|
1077
|
+
const cleanApiKey = apiKey.trim();
|
|
1078
|
+
const hashedKey = createHash("sha256").update(cleanApiKey).digest("hex");
|
|
1078
1079
|
const clientKey = SUPABASE_SERVICE_KEY || SUPABASE_ANON_KEY;
|
|
1079
1080
|
const supabase = createSupabaseClient(SUPABASE_URL, clientKey);
|
|
1080
|
-
const { data: keyData, error: keyError } = await supabase.
|
|
1081
|
+
const { data: keyData, error: keyError } = await supabase.rpc("authenticate_api_key_hash", { hash: hashedKey }).single();
|
|
1081
1082
|
if (keyError || !keyData) {
|
|
1082
1083
|
return { success: false, error: "Invalid or revoked API key" };
|
|
1083
1084
|
}
|
|
1084
|
-
|
|
1085
|
+
const { id, user_id } = keyData;
|
|
1085
1086
|
const userSupabase = createSupabaseClient(SUPABASE_URL, clientKey);
|
|
1086
1087
|
return {
|
|
1087
1088
|
success: true,
|
|
1088
1089
|
context: {
|
|
1089
|
-
userId:
|
|
1090
|
-
apiKeyId:
|
|
1090
|
+
userId: user_id,
|
|
1091
|
+
apiKeyId: id,
|
|
1091
1092
|
supabase: userSupabase
|
|
1092
1093
|
}
|
|
1093
1094
|
};
|