Skip to content

Commit

Permalink
provide sid in auth.getUser
Browse files Browse the repository at this point in the history
  • Loading branch information
prostgles committed Dec 21, 2024
1 parent 47d9bda commit fc246db
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ prostgles<DBGeneratedSchema>({
Data access rules applied to clients.
By default, nothing is allowed.

- **publishRawSQL** <span style="color: grey">optional</span> <span style="color: green;">(params: PublishParams&lt;S, SUser&gt;) =&gt; boolean | "*" | Promise&lt;boolean | "*"&gt;</span>
- **publishRawSQL** <span style="color: grey">optional</span> <span style="color: green;">(params: PublishParams&lt;S, SUser&gt;) =&gt; Awaitable&lt;boolean | "*"&gt;</span>

If defined and resolves to true then the connected client can run SQL queries

Expand Down Expand Up @@ -194,7 +194,7 @@ prostgles<DBGeneratedSchema>({

Name of the cookie or socket hadnshake query param that represents the session id.
Defaults to "session_id"
- **getUser** <span style="color: red">required</span> <span style="color: green;">(sid: string | undefined, dbo: DBOFullyTyped&lt;S&gt;, db: DB, client: AuthClientRequest & LoginClientInfo) =&gt; Awaitable&lt;AuthResult&lt;...&gt;&gt;</span>
- **getUser** <span style="color: red">required</span> <span style="color: green;">(sid: string | undefined, dbo: DBOFullyTyped&lt;S&gt;, db: DB, client: AuthClientRequest & LoginClientInfo) =&gt; Awaitable&lt;AuthResultOrError&lt;...&gt;&gt;</span>

undefined sid is allowed to enable public users
- **expressConfig** <span style="color: grey">optional</span> <span style="color: green;">ExpressConfig</span>
Expand Down
5 changes: 3 additions & 2 deletions lib/Auth/AuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
AuthClientRequest,
AuthResult,
AuthResultOrError,
AuthResultWithSID,
BasicSession,
ExpressReq,
ExpressRes,
Expand Down Expand Up @@ -145,7 +146,7 @@ export class AuthHandler {
}
};

getUserAndHandleError = async (localParams: AuthClientRequest): Promise<AuthResult> => {
getUserAndHandleError = async (localParams: AuthClientRequest): Promise<AuthResultWithSID> => {
const sid = this.getSID(localParams);
if (!sid) return undefined;
const handlerError = (code: AuthFailure["code"]) => {
Expand All @@ -170,7 +171,7 @@ export class AuthHandler {
return handlerError(userOrErrorCode);
}

return userOrErrorCode;
return { sid, ...userOrErrorCode };
} catch (_err) {
return handlerError("server-error");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Auth/AuthTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export type AuthResultOrError<SU = SessionUser> = AuthFailure["code"] | AuthResu
export type AuthRequestParams<S, SUser extends SessionUser> = {
db: DB;
dbo: DBOFullyTyped<S>;
getUser: () => Promise<AuthResultOrError<SUser>>;
getUser: () => Promise<AuthResultWithSID<SUser>>;
};

export type Auth<S = void, SUser extends SessionUser = SessionUser> = {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prostgles-server",
"version": "4.2.192",
"version": "4.2.193",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion tests/server/package-lock.json

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

0 comments on commit fc246db

Please sign in to comment.