Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cookie-based authentication #3769

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/react-components/auth/AuthContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import configs from "../../utils/configs";
// TODO: We really shouldn't include these dependencies on every page. A dynamic import would work better.
import jwtDecode from "jwt-decode";
import AuthChannel from "../../utils/auth-channel";
import { connectToReticulum } from "../../utils/phoenix-utils";
import { connectToReticulum, getReticulumFetchUrl } from "../../utils/phoenix-utils";

export const AuthContext = createContext();

Expand Down Expand Up @@ -65,6 +65,12 @@ export function AuthContextProvider({ children, store }) {
const socket = await connectToReticulum();
authChannel.setSocket(socket);
await authChannel.verifyAuthentication(authParams.topic, authParams.token, authParams.payload);
await fetch(getReticulumFetchUrl("/api/v1/accounts/set_cookie"), {
johnshaughnessy marked this conversation as resolved.
Show resolved Hide resolved
method: "GET",
johnshaughnessy marked this conversation as resolved.
Show resolved Hide resolved
headers: {
authorization: `bearer ${store.state.credentials.token}`
}
});
},
[store]
);
Expand All @@ -74,6 +80,9 @@ export function AuthContextProvider({ children, store }) {
configs.setIsAdmin(false);
store.update({ credentials: { token: null, email: null } });
await store.resetToRandomDefaultAvatar();
await fetch(getReticulumFetchUrl("/api/v1/accounts/expire_cookie"), {
method: "GET"
});
},
[store]
);
Expand Down