Skip to content

Commit

Permalink
fix: fix issue with sign in with microsoft
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Nov 19, 2023
1 parent 22045ec commit cc7df5a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/components/Authentication/Kratos/KratosLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Login: NextPage = () => {
})
.then(({ data }) => {
setFlow(data);
SetUriFlow(Router, data.id);
SetUriFlow(Router, data.id, returnTo);
})
.catch(handleError),
[handleError]
Expand Down
17 changes: 15 additions & 2 deletions src/components/ory/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@

import { NextRouter } from "next/router";

export const SetUriFlow = (router: NextRouter, id: string) => {
export const SetUriFlow = (
router: NextRouter,
id: string,
returnTo: string
) => {
// Check that current query flow id does not match requested one - pushing will trigger useEffect if router bound
if (router.query.flow === id) {
return;
}

router.push(`${router.pathname}?flow=${id}`, undefined, { shallow: true });
router.push(
`${router.pathname}`,
{
query: {
return_to: returnTo,
flow: id
}
},
{ shallow: true }
);
};
10 changes: 4 additions & 6 deletions src/components/ory/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,10 @@ export function useCreateLogoutHandler(deps?: DependencyList) {
const handleError = HandleError();
const { push } = useRouter();

const returnTo = useMemo(() => {
if (typeof window !== "undefined") {
return window.location.pathname + window.location.search;
}
return undefined;
}, []);
const returnTo =
typeof window !== "undefined"
? window.location.pathname + window.location.search
: undefined;

useEffect(() => {
ory
Expand Down
68 changes: 33 additions & 35 deletions src/components/ory/ui/Flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,42 +201,40 @@ export class Flow<T extends Values> extends Component<Props<T>, State<T>> {
/>
);
})}
<hr className="border-gray-200 my-3" />
<div className="flex flex-col">
{filterNodesByGroups({
nodes: nodes,
groups: ["oidc", "webauthn"],
withoutDefaultGroup: true
}).map((node, k) => {
const id = getNodeId(node) as keyof Values;
return (
<Node
key={`${id}-${k}`}
disabled={isLoading}
node={node}
value={values[id]}
dispatchSubmit={this.handleSubmit}
setValue={(value) =>
new Promise((resolve) => {
this.setState(
(state) => ({
...state,
values: {
...state.values,
[getNodeId(node)]: value
}
}),
resolve
);
})
}
/>
);
})}
</div>
</form>

<hr className="border-gray-200 my-3" />

<div className="flex flex-col">
{filterNodesByGroups({
nodes: nodes,
groups: ["oidc", "webauthn"],
withoutDefaultGroup: true
}).map((node, k) => {
const id = getNodeId(node) as keyof Values;
return (
<Node
key={`${id}-${k}`}
disabled={isLoading}
node={node}
value={values[id]}
dispatchSubmit={this.handleSubmit}
setValue={(value) =>
new Promise((resolve) => {
this.setState(
(state) => ({
...state,
values: {
...state.values,
[getNodeId(node)]: value
}
}),
resolve
);
})
}
/>
);
})}
</div>
</div>
);
}
Expand Down

0 comments on commit cc7df5a

Please sign in to comment.