Skip to content

Commit

Permalink
Add more debugging for auth issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakycrow committed Dec 24, 2024
1 parent e95a617 commit bb8739c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
26 changes: 15 additions & 11 deletions k8s/overlays/staging/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,31 @@ metadata:
nginx.ingress.kubernetes.io/real-ip-header: "X-Forwarded-For"
nginx.ingress.kubernetes.io/proxy-real-ip-cidr: "173.245.48.0/20,103.21.244.0/22,103.22.200.0/22,103.31.4.0/22,141.101.64.0/18,108.162.192.0/18,190.93.240.0/20,188.114.96.0/20,197.234.240.0/22,198.41.128.0/17,162.158.0.0/15,104.16.0.0/13,104.24.0.0/14,172.64.0.0/13,131.0.72.0/22"
# Cors settings
nginx.ingress.kubernetes.io/proxy-set-headers: "ingress-nginx/custom-headers"
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "https://staging.farmhand.witchscrow.com"
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
nginx.ingress.kubernetes.io/cors-allow-methods: "GET, POST, PUT, DELETE, OPTIONS"
nginx.ingress.kubernetes.io/cors-allow-headers: "DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization"
nginx.ingress.kubernetes.io/configuration-snippet: |
more_set_headers "Access-Control-Allow-Origin: $http_origin";
more_set_headers "Access-Control-Allow-Credentials: true";
more_set_headers "Access-Control-Allow-Headers: Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Access-Control-Request-Method,Access-Control-Request-Headers";
more_set_headers "Access-Control-Allow-Methods: GET,POST,OPTIONS,PUT,DELETE";
proxy_hide_header Access-Control-Allow-Origin;
proxy_hide_header Access-Control-Allow-Methods;
proxy_hide_header Access-Control-Allow-Headers;
proxy_set_header Authorization $http_authorization;
proxy_pass_header Authorization;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '$http_origin';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Access-Control-Request-Method,Access-Control-Request-Headers';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE';
add_header 'Access-Control-Allow-Origin' '$http_origin' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type' always;
add_header 'Access-Control-Max-Age' 1728000;
return 204;
}
proxy_set_header Authorization $http_authorization;
proxy_pass_header Authorization;
add_header 'Access-Control-Allow-Origin' '$http_origin' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type' always;
spec:
ingressClassName: nginx
tls:
Expand Down
21 changes: 17 additions & 4 deletions services/barn-ui/src/lib/server/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,35 @@ export enum UserError {

export const getTokenIdentity = async (token: string): Promise<User | null> => {
try {
// Fetch user data from your API
console.log('Sending request with token:', token); // Debug log

const headers = {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
Origin: 'https://staging.farmhand.witchscrow.com'
};

console.log('Request headers:', headers); // Debug log

const response = await fetch(`${env.API_URL}/user/me`, {
headers: {
Authorization: `Bearer ${token}`
},
method: 'GET',
headers,
credentials: 'include',
mode: 'cors'
});

console.log('Response status:', response.status); // Debug log
console.log('Response headers:', Object.fromEntries(response.headers)); // Debug log

if (response.ok) {
const userData: User = await response.json();
return userData;
} else {
console.error('Response not OK:', await response.text()); // Debug log
throw UserError.INVALID_TOKEN;
}
} catch (e) {
console.error('Error in getTokenIdentity:', e); // Debug log
if (e === UserError.INVALID_TOKEN) {
throw e;
}
Expand Down

0 comments on commit bb8739c

Please sign in to comment.