Skip to content

Commit

Permalink
fix: handle invalid creds on login
Browse files Browse the repository at this point in the history
  • Loading branch information
jrea committed May 18, 2023
1 parent 4df1d9f commit f18cec6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
12 changes: 8 additions & 4 deletions packages/server/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ export default class Auth extends Config {
return res.response;
}

const token = await res.json();
const cookie = `${this.api?.cookieKey}=${token.jwt}; path=/; samesite=lax; httponly;`;
headers.set('set-cookie', cookie);
return new Response(JSON.stringify(token), { status: 200, headers });
if (res && res.status >= 200 && res.status < 300) {
const token = await res.json();
const cookie = `${this.api?.cookieKey}=${token.jwt}; path=/; samesite=lax; httponly;`;
headers.set('set-cookie', cookie);
return new Response(JSON.stringify(token), { status: 200, headers });
}
const text = await res.text();
return new Response(text, { status: res.status });
};

get signUpUrl() {
Expand Down
16 changes: 10 additions & 6 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Server {
users: Users;
};
db: Knex;
_tenantId: string | undefined;

constructor(config: ServerConfig) {
this.config = new Config(config);
Expand All @@ -27,14 +28,17 @@ class Server {
};
this.db = knex(dbConfig);
}
get tenantId() {
return this.tenantId;

get tenantId(): string | undefined {
return this.config.tenantId;
}

set tenantId(tenantId: string) {
this.config.tenantId = tenantId;
this.api.auth.tenantId = tenantId;
this.api.users.tenantId = tenantId;
set tenantId(tenantId: string | undefined) {
if (tenantId) {
this.config.tenantId = tenantId;
this.api.auth.tenantId = tenantId;
this.api.users.tenantId = tenantId;
}
}
}

Expand Down

0 comments on commit f18cec6

Please sign in to comment.